如何解析kubectl Describe输出并获取所需的字段值 [英] How to parse kubectl describe output and get the required field value

查看:9
本文介绍了如何解析kubectl Describe输出并获取所需的字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用kubectl Describe命令从特定Pod获取Nodeport。从这个question我了解到-o选项不适用于DESCRIBE,因此我尝试了以下方法,但我没有获得所需的值,有人能纠正我吗?

kubectl -n core describe svc/pg-debug
Name:                     pg-debug
Namespace:                core
Labels:                   <none>
Annotations:              <none>
Selector:                 app=postgresql-default
Type:                     NodePort
IP:                       172.17.17.19
Port:                     <unset>  5432/TCP
TargetPort:               5432/TCP
NodePort:                 <unset>  24918/TCP
Endpoints:                172.16.90.10:5432
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

以下是我尝试获取的值"24918"

的命令
kubectl -n core describe svc/pg-debug | grep NodePort |awk -F:  '/nodePort/{gsub(/ /,"",$2)}'

推荐答案

您可以使用以下命令从服务中获取nodePort

kubectl get svc pg-debug -n core -o jsonpath='{.spec.ports[].nodePort}'

参考文献:

这篇关于如何解析kubectl Describe输出并获取所需的字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆