指定仅使用CLI显示资源的Kubernetes名称空间
是否可以使用多个指定namepaces
的Kubernetes(K8S)资源使用 唯一的 CLI(kubectl
)?
换句话说,在k8s群集中给定两个名称空间
:
kubectl get namespaces \
--output=go-template \
--template='{{ range .items }}{{ .metadata.name }}{{ "\n" }}{{ end }}'
#=>
. . .
$SOME_NAMESPACE
. . .
$ANOTHER_NAMESPACE
. . .
仅从中get
资源(例如pods
)使用 唯一的>
kubectl
?
提供- 全名空间
标志和使用- field-selector
或- selector
标志将 not not < /strong>工作,因为两个标志仅接受=
,==
和!=
运算符。
Is it possible to display Kubernetes (K8s) resources from multiple specified namespaces
with only the CLI (kubectl
)?
In other words, given two namespaces
in a K8s cluster:
kubectl get namespaces \
--output=go-template \
--template='{{ range .items }}{{ .metadata.name }}{{ "\n" }}{{ end }}'
#=>
. . .
$SOME_NAMESPACE
. . .
$ANOTHER_NAMESPACE
. . .
would it be possible to get
resources (such as pods
) from only those two namespaces
($SOME_NAMESPACE
and $ANOTHER_NAMESPACE
) using only kubectl
?
Supplying the --all-namespaces
flag and filtering using either the --field-selector
or --selector
flags will not work, because both flags accept only =
, ==
and !=
operators.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
go-template
打印属于两个名称空间的POD的名称,以下是从test> test-1
和test打印POD的示例-2
名称空间。You may use
go-template
to print the name of the pods belonging to the two namespaces, following is an example of printing pods from thetest-1
andtest-2
namespace.根据的讨论当前不可用可以指定多个名称空间:单独使用
- 单独使用
标志,或者使用过滤标志(例如- selector
)。您 can 目前,使用诸如bash brace扩展的解决方法,如建议此处,或用
命令
- All-Namespaces
flag flag flag awk :According to the discussion that has already occurred in this GitHub issue, it does not currently seem possible to specify multiple namespaces: either with just the
--namespace
flag alone or using a filtering flag such as--selector
.You can, for now, use workarounds such as Bash brace expansion, as suggested here, or feeding the output of the
get
command with the--all-namespaces
flag intoawk
: