通过kubectl ingress-nginx命令,可以查看在ingress controller中,有哪些backends,每个backends的后端的endpoints信息和对应其他的参数设置
比如:
kubectl ingress-nginx backends -n ingress-nginx
[root@nccztsjb-node-23 data]# kubectl ingress-nginx backends -n ingress-nginx [ { "name": "default-nginx-deployment-80", "service": { "metadata": { "creationTimestamp": null }, "spec": { "ports": [ { "protocol": "TCP", "port": 80, "targetPort": 80 } ], "selector": { "app": "nginx" }, "clusterIP": "10.98.87.101", "clusterIPs": [ "10.98.87.101" ], "type": "ClusterIP", "sessionAffinity": "ClientIP", "sessionAffinityConfig": { "clientIP": { "timeoutSeconds": 10800 } }, "ipFamilies": [ "IPv4" ], "ipFamilyPolicy": "SingleStack", "internalTrafficPolicy": "Cluster" }, "status": { "loadBalancer": {} } }, "port": 80, "sslPassthrough": false, "endpoints": [ { "address": "172.39.157.239", "port": "80" }, { "address": "172.39.21.93", "port": "80" }, { "address": "172.39.21.95", "port": "80" } ], "sessionAffinityConfig": { "name": "", "mode": "", "cookieSessionAffinity": { "name": "" } }, "upstreamHashByConfig": { "upstream-hash-by-subset-size": 3 }, "noServer": false, "trafficShapingPolicy": { "weight": 0, "weightTotal": 0, "header": "", "headerValue": "", "headerPattern": "", "cookie": "" } }, { "name": "upstream-default-backend", "port": 0, "sslPassthrough": false, "endpoints": [ { "address": "127.0.0.1", "port": "8181" } ], "sessionAffinityConfig": { "name": "", "mode": "", "cookieSessionAffinity": { "name": "" } }, "upstreamHashByConfig": {}, "noServer": false, "trafficShapingPolicy": { "weight": 0, "weightTotal": 0, "header": "", "headerValue": "", "headerPattern": "", "cookie": "" } } ]
如果这个数据很多,想要查看到底有哪些的backends呢?
可以使用jq工具,可以将数据转换为json格式,然后选择出来某个字段
kubectl ingress-nginx backends -n ingress-nginx | jq ".[].name"
[root@nccztsjb-node-23 data]# kubectl ingress-nginx backends -n ingress-nginx | jq ".[].name" "default-nginx-deployment-80" "upstream-default-backend" [root@nccztsjb-node-23 data]#
jq工具,可以通过
yum install -y jq
来进行安装
这样呢,就可获取到了所有的backends的信息
然后,这个时候呢,就可以获取某个特定的backends的信息了,比如:
使用--backend参数
kubectl ingress-nginx backends -n ingress-nginx --backend default-nginx-deployment-80
[root@nccztsjb-node-23 data]# kubectl ingress-nginx backends -n ingress-nginx --backend default-nginx-deployment-80 { "endpoints": [ { "address": "172.39.157.239", "port": "80" }, { "address": "172.39.21.93", "port": "80" }, { "address": "172.39.21.95", "port": "80" } ], "name": "default-nginx-deployment-80", "noServer": false, "port": 80, "service": { "metadata": { "creationTimestamp": null }, "spec": { "clusterIP": "10.98.87.101", "clusterIPs": [ "10.98.87.101" ], "internalTrafficPolicy": "Cluster", "ipFamilies": [ "IPv4" ], "ipFamilyPolicy": "SingleStack", "ports": [ { "port": 80, "protocol": "TCP", "targetPort": 80 } ], "selector": { "app": "nginx" }, "sessionAffinity": "ClientIP", "sessionAffinityConfig": { "clientIP": { "timeoutSeconds": 10800 } }, "type": "ClusterIP" }, "status": { "loadBalancer": {} } }, "sessionAffinityConfig": { "cookieSessionAffinity": { "name": "" }, "mode": "", "name": "" }, "sslPassthrough": false, "trafficShapingPolicy": { "cookie": "", "header": "", "headerPattern": "", "headerValue": "", "weight": 0, "weightTotal": 0 }, "upstreamHashByConfig": { "upstream-hash-by-subset-size": 3 } }
还可以查看这个backend的endpoints
[root@nccztsjb-node-23 data]# kubectl ingress-nginx backends -n ingress-nginx --backend default-nginx-deployment-80 | jq ".endpoints" [ { "address": "172.39.157.239", "port": "80" }, { "address": "172.39.21.93", "port": "80" }, { "address": "172.39.21.95", "port": "80" } ] [root@nccztsjb-node-23 data]#
这里面,主要是借助了jq这个工具,对输出进行格式化,对某个字段值的值进行选择。
标签:ingress,name,nginx,controller,backends,80,port,backend From: https://www.cnblogs.com/chuanzhang053/p/17479780.html