使用curl调用k8s apiserver接口如何通过ingress配置中的host字段和servicePort字段内容进行过滤用以获取到符合要求的ingress对象
要通过curl调用Kubernetes API服务器接口,并根据Ingress配置中的host和servicePort字段内容进行过滤,可以使用以下步骤:
-
获取所有Ingress对象:
curl -X GET https://<api-server-url>/apis/networking.k8s.io/v1/ingresses -H "Authorization: Bearer <token>" -
过滤Ingress对象: 在获取到的Ingress对象列表中,可以使用jq工具进行过滤。假设你想要获取host为example.com,且servicePort为80的Ingress对象,可以使用以下命令进行过滤:
curl -X GET https://<api-server-url>/apis/networking.k8s.io/v1/ingresses -H "Authorization: Bearer <token>" | jq '.items[] | select(.spec.rules[].host == "example.com" and .spec.rules[].http.paths[].backend.service.port.number == 80)'注意:上述命令中的
<api-server-url>应替换为实际的API服务器URL,<token>应替换为有效的认证令牌。
通过以上步骤,你可以使用curl调用Kubernetes API服务器接口,并根据Ingress配置中的host和servicePort字段内容进行过滤,以获取到符合要求的Ingress对象
原文地址: https://www.cveoy.top/t/topic/iyid 著作权归作者所有。请勿转载和采集!