小编Var*_*ini的帖子

使用 shell 脚本提取 kubernetes pod 名称

我想从 kubernetes 上可用的 pod 列表中提取 pod 名称。例如,对于以下命令

kubectl get pods -n 命名空间

NAME          READY   STATUS            RESTARTS   AGE
pod1          1/1     Running           2          46d
pod2          1/1     Running           0          46d
test-pod3-yy  0/1     ImagePullBackOff  0          338d
test-pod3-xx  1/1     Running           0          255d
Run Code Online (Sandbox Code Playgroud)

test-pod3-xx我想使用 shell 脚本提取 pod 。目前这是我正在使用的命令

POD_NAME=$(kubectl get pods -n namespace | grep testpod-3 | cut -d' ' -f1)
Run Code Online (Sandbox Code Playgroud)

这样我就得到了两个 Pod test-pod3-yytest-pod3-xx但我想提取处于运行状态的 Pod。我怎样才能做到这一点?

bash shell grep kubernetes kubectl

0
推荐指数
1
解决办法
1805
查看次数

标签 统计

bash ×1

grep ×1

kubectl ×1

kubernetes ×1

shell ×1