首页 > 其他分享 >kubectl -o go-template

kubectl -o go-template

时间:2022-11-02 20:03:15浏览次数:82  
标签:kubectl name nginx template go pod

关于golang的text/template

http://docs.studygolang.com/pkg/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

标签:kubectl,name,nginx,template,go,pod
From: https://www.cnblogs.com/cosmos-wong/p/16852198.html

相关文章

  • kubectl get pod -w
    -w,--watch=false:Afterlisting/gettingtherequestedobject,watchforchanges.Uninitializedobjectsareexcludedifnoobjectnameisprovided.--w......
  • error in ./src/assets/images/logo.png报错
    vue项目启动执行时报错找不到图片,errorin./src/assets/images/logo.png解决:先卸载再重新安装image-webpack-loadernpmuninstallimage-webpack-loadercnpminsta......
  • mongodb第四篇:sharding
    开启分片:1、先对数据库开启分片切换到admin数据库,执行db.runCommand({"enablesharding":"$db_name"})2、再对数据库中某集合开启分片切换到admin数据库,执行db.runCom......
  • RedisTemplate自适应Redis配置模式config
    RedisTemplate配置Java源码:importcom.fasterxml.jackson.annotation.JsonAutoDetect;importcom.fasterxml.jackson.annotation.PropertyAccessor;importcom.fasterx......
  • Mongodb修改oplog大小--笔记
    MongoDB3.6之前oplog修改需要重启实例到非副本单实例模式,3.6开始可以使用命令replSetResizeOplog在线修改副本集成员的oplog大小。修改方式为:先修改从secondary节点开,然后......
  • git clone https://chromium.googlesource.com/chromium/tools/depot_tools 下载时超
    解决方案1我这里使用的是极光,端口是......
  • Go语言 实现一个简单生产者消费者模型,你是如何实现的?
    Go语言实现一个简单生产者消费者模型,你是如何实现的?Go语言圈 2022-10-3108:30 发表于广东学习与交流:Go语言技术微信群商务合作加微信:LetsFenggoland全家桶激活码......
  • DJango + Vue 文件下载
    后端importrequestsfromdjango.httpimportFileResponsefromdjango.utils.encodingimportescape_uri_pathdefdownload_file(request): ifrequest.method==......
  • MongoDB副本集搭建
    一、安装mongodb服务   1、下载mongodb二进制包,解压,移动到/usr/local/下。tarzxfmongodb-linux-x86_64-rhel70-4.4.17.tgzmvmongodb-linux-x86_64-rhel70-4.4......
  • Django当中如何实现用xlwt来导出一个excel文件?
     将数据导出到excel表格中,也算是我们开发中经常用到的功能,这里用到了python的xlwt模块。 1、安装xlwt模块在你的django虚拟环境中安装:1pipinstallxlwt2.mod......