kubectl -o go-template
关于golang的text/template
$ cat <<EOF |kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
shareProcessNamespace: true
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
- name: shell
image: busybox
imagePullPolicy: IfNotPresent
securityContext:
capabilities:
add:
- SYS_PTRACE
stdin: true
tty: true
EOF
查看Kind:
$ kubectl get pod nginx -o go-template='{{.kind}}'
Pod
查看POD的name:
$ kubectl get pod nginx -o go-template='{{.metadata.name}}'
nginx
查看镜像名称和镜像:
简单点的:
$ kubectl get pod nginx -o go-template='{{range .spec.containers}}{{printf "name:%v,images:%v\n" .name .image}}{{end}}'
name:nginx,images:nginx
name:shell,images:busybox
复杂点的:
kubectl get pod nginx -o go-template='<<EOF
The pod has two containers:
{{range $index,$elem:=.spec.containers}}
===========================
{{$index}}: name:{{$elem.name}} image:{{$elem.image}}
{{end}}'
EOF
输出结果:
[root@k8s-node1 ~]# kubectl get pod nginx -o go-template='<<EOF
> The pod has two containers:
> {{range $index,$elem:=.spec.containers}}
> ===========================
> {{$index}}: name:{{$elem.name}} image:{{$elem.image}}
> {{end}}'
<<EOF
The pod has two containers:
===========================
0: name:nginx image:nginx
===========================
1: name:shell image:busybox
参考链接:https://www.cnblogs.com/summershan/p/15672179.html
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
分类:
Kubernetes
标签:
K8S
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程