以单词开头时删除所有

以单词开头时删除所有

本文介绍了以单词开头时删除所有 pod(不完整的 pod 名称)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 OC 中有一些项目,Pod 的名称是在链和提交的基础上生成的.所以,我想在 AzureDevOps 中创建一个指令,删除所有 pod 的名称不完整,名称带有特定字符,但用其他字符完成.

I have some projects in OC, and the names of the pods are generated in base of a chain and a commit. So, I want create an instruction in AzureDevOps to delete all the pods by an incomplete name the name with an specific characters, but finishing with others.

示例:

root@oc-jump-pod:/# oc get po
NAME                           READY     STATUS    RESTARTS   AGE
podA-74rt7                     1/1       Running   0          20h
podB-6744849c59                1/1       Running   0          20h
podB-6746378213                1/1       Running   0          20h

我需要使用类似的东西:

I need use something like:

oc delete po podB*
Error from server (NotFound): pods "podB*" not found

如何使用几个字符而不是 Pod 的完整名称来过滤删除?

How can I filter the deletion with a couple of characters and not the complete name of the pod?

已添加 DeployConfig:

DeployConfig added:

root@oc-jump-pod-pre:/# oc describe deploy NAME
Name:                   NAME
Namespace:              NAME-pre
CreationTimestamp:      Mon, 25 May 2020 07:01:14 +0000
Labels:                 app.kubernetes.io/instance=NAME
                        app.kubernetes.io/managed-by=Helm
                        app.kubernetes.io/name=NAME
                        app.kubernetes.io/version=latest
                        helm.sh/chart=NAME-1.0.0
Annotations:            deployment.kubernetes.io/revision=3
                        meta.helm.sh/release-name=NAME
                        meta.helm.sh/release-namespace=sda-NAME-pre
Selector:               app.kubernetes.io/instance=NAME,app.kubernetes.io/name=NAME
Replicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:           app.kubernetes.io/instance=NAME
                    app.kubernetes.io/name=NAME
  Service Account:  default
  Containers:
   NAME:
    Image:  registry/sda-NAME-dev/test-NAME-java:0.0.2
    Port:   8080/TCP
    Limits:
      cpu:     150m
      memory:  1444Mi
    Requests:
      cpu:     100m
      memory:  1Gi
    Environment:
      APP_NAME:                     NAME
      JAVA_OPTS_EXT:                ....
      SPRING_CLOUD_CONFIG_PROFILE:  pre
      TZ:                           Europe/Madrid
      WILY_MOM_PORT:                5001
      spring_application_name:      NAME_pre
      spring_cloud_config_uri:      https://config.d.cluster.local
    Mounts:
      /etc/jks from jks (ro)
      /etc/secret-vol from secretvol (ro)
      /etc/truststore from jssecacerts (ro)
  Volumes:
....
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Progressing    True    NewReplicaSetAvailable
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  NAME-6744849c59 (1/1 replicas created)
NewReplicaSet:   <none>
Events:          <none>

推荐答案

对于基于正则表达式的方法,以下命令将删除所有以podB"开头的 Pod

For regex based approach following commands will delete all the pods starting with "podB"

oc get pods | awk '/^podB/{system("oc delete pod " $1)}'

无论如何,我会推荐使用 Dashrath Mundkar 提供的方法.对于 openshift,如果您只想访问当前项目中的资源,则不需要提供任何命名空间,因此您只需删除-n 命名空间"即可.来自像

Anyway i would recommend using the method provided by Dashrath Mundkar.For openshift you do not need to provide any namespace if you just want to access resource in your current project so you can just remove the "-n namespace" from the commands like

oc get pod -l labelname=value
oc delete pod -l labelname=value

只需确保您提供的标签对于您要删除的 Pod 来说是唯一的

Just make sure the labels you provided are unique to pods you want to delete

这篇关于以单词开头时删除所有 pod(不完整的 pod 名称)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 19:02