kubernetes - 如何解析 kubectl describe 输出并获取所需的字段值
问题描述
我正在尝试使用 kubectl describe 命令从特定 pod 获取 Nodeport。我从这个问题中了解到 -o 选项不适用于描述,因此我正在尝试以下方式,但我没有得到所需的值,有人可以纠正我。
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}'
参考:
推荐阅读
- r - 将纽约州法院数据中的数据转换为要可视化的数据框 R(导入但未成为正确的数据框)
- git - git-svn 死于信号 11
- java - 如何使用 kotlin 或 java 将倒数计时器设置为一天中的特定时间?
- python - 如何在 tkinter 中的屏幕/帧之间切换?
- jupyter-notebook - 无法在 OSX 10.11 中使用 xeus-cling 内核
- android - 如何在 Android Studio 中添加 gradle 的任务参数?
- sql - Only SubQuery expressions that are top level conjuncts are allowed error
- go - HTTP GET,来自特定本地 IP,使用备用 DNS
- sql - “缺少右括号”
- php - Laravel 播种器:调用未定义的方法 Illuminate\Notifications\Notification::getConnectionName()