kubectl之jsonpath笔记

kubectl之jsonpath笔记

jsonpath

FunctionDescriptionExampleResult
textthe plain textkind is {.kind}kind is List
@the current object{@}the same as input
. or []child operator{.kind} or {[‘kind’]}List
recursive descent{…name}127.0.0.1 127.0.0.2 myself e2e
*wildcard. Get all objects{.items[*].metadata.name}[127.0.0.1 127.0.0.2]
[start:end :step]subscript operator{.users[0].name}myself
[,]union operator{.items[*][‘metadata.name’, ‘status.capacity’]}127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]
?()filter{.users[?(@.name==“e2e”)].user.password}secret
range, enditerate list{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]]
quote interpreted string{range .items[*]}{.metadata.name}{’\t’}{end}127.0.0.1 127.0.0.2
  1. 查询镜像以及副本数
kubectl get deployment -n namespace -o jsonpath='{range .items[*]}[{.spec.template.spec.containers[*].image},{.spec.replicas}]{end}'|tr -s '[[:space:]]' '\n'|uniq
  1. 副本数为零的镜像
kubectl get deployment -n namespace -o jsonpath='{.items[?(@.spec.replicas==0)].spec.template.spec.containers[*].image}'|tr -s '[[:space:]]' '\n'|uniq
  1. 检查是否添加探活
kubectl get deploy -n namespace-o jsonpath='{range .items[*]}[{.spec.template.spec.containers[*].livenessProbe.initialDelaySeconds},{.metadata.name}]{"\n"}{end}'
kubectl get deploy -n namespace -o jsonpath='{range .items[*]}[{.spec.template.spec.containers[*].readinessProbe.initialDelaySeconds},{.metadata.name}]{"\n"}{end}'
  1. 查询初始化容器镜像
kubectl get deployment -A -o jsonpath='{range .items[?(@.spec.template.spec.initContainers)]}{.metadata.namespace},{.metadata.name},{.spec.template.spec.initContainers[*].image}{"\n"}{end}'
  1. 按照时间搜集项目,部署集群(规格,几个Pod)
kubectl get deploy -n kube-system --sort-by=.metadata.creationTimestamp -ojsonpath='{range .items[*]}{.metadata.creationTimestamp}{"\t"}{.spec.replicas}{"\t"}{.metadata.namespace}{"\t"}{.metadata.name
}{"\t\t\t"}{.spec.template.spec.containers[*].resources}{"\n"}{end}'

6.查询deploy及容器资源配置

 kubectl get deployment -n namespace -o jsonpath='{range .items[*]}[{.spec.template.spec.containers[*].resources},{.metadata.name},{.spec.template.spec.containers[*].name}] {"\n"}{end}'

7.查询deploy镜像

 kubectl get deploy -o custom-columns=CONTAINER:.spec.template.spec.containers[0].name,IMAGE:.spec.template.spec.containers[0].image -n ns

8.查询deploy的第一个contianer的name

 kubectl get deploy -o custom-columns=CONTAINER:.spec.template.spec.containers[0].name
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值