如何解析 kubectl describe 输出并获取所需的字段值
How to parse kubectl describe output and get the required field value
我正在尝试使用 kubectl describe 命令从特定 pod 获取 Nodeport。我从这个 了解到 -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(/ /,"",)}'
您可以使用以下命令从服务中获取节点端口
kubectl get svc pg-debug -n core -o jsonpath='{.spec.ports[].nodePort}'
参考文献:
我正在尝试使用 kubectl describe 命令从特定 pod 获取 Nodeport。我从这个
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(/ /,"",)}'
您可以使用以下命令从服务中获取节点端口
kubectl get svc pg-debug -n core -o jsonpath='{.spec.ports[].nodePort}'
参考文献: