【发布时间】:2020-04-02 04:09:54
【问题描述】:
团队,
我能够获取在具有其命名空间的节点上运行的所有 pod,但我的命名空间是动态生成的,并且它们最终会随着字符而变化。有没有一种方法可以包含一个正则表达式/模式,我可以在 kubectl 命令中使用它来从所有匹配的命名空间中提取所有 pod?
kubectl get pods -n team-1-user1 --field-selector=spec.nodeName=node1,status.phase=Running
实际输出1:有效
NAMESPACE NAME READY STATUS RESTARTS AGE
team-1-user1 calico-node-9j5k2 1/1 Running 2 104d
team-1-user1 kube-proxy-ht7ch 1/1 Running 2 130d
我想在下面为所有以“team-”开头的命名空间拉取 pod。
kubectl get pods -n team-* --field-selector=spec.nodeName=node1,status.phase=Running
实际输出2:失败
No resources found in team-workflow-2134-asf-324-d.yaml namespace.
预期结果:想要这个..
NAMESPACE NAME READY STATUS RESTARTS AGE
team-1-user1 calico-node-9j5k2 1/1 Running 2 104d
team-1-user1 kube-proxy-ht7ch 1/1 Running 2 130d
team-2-user1 calico-node-9j5k2 1/1 Running 2 1d
team-2-user1 kube-proxy-ht7ch 1/1 Running 2 10d
【问题讨论】:
-
不,您不能使用 glob 或正则表达式。您可以做的是使用标签进行查询。类似
kubectl get pods -l mylabel=myvalue --all-namespaces -
但是我的命名空间没有在标签下列出或者我不理解这个建议。
标签: regex bash awk sed kubectl