我正在尝试从入口规则中删除具有后端的路径,但无法完全正常工作。
这是我尝试删除它的方式:
// get path to delete
Optional<HTTPIngressPath> pathToDelete = kubernetesClient.extensions().ingresses().withName("my-ingress")
.get()
.getSpec()
.getRules()
.get(0)
.getHttp()
.getPaths().stream()
.filter(path -> path.getBackend().getServiceName().equals(buildServiceNameById(id))).findFirst();
if(!pathToDelete.isPresent()) {
LOGGER.warn("Couldn't determine ingress path for " + buildServiceNameById(id) + ".");
return;
}
kubernetesClient.extensions().ingresses().withName("my-ingress")
.edit()
.editSpec()
.editFirstRule()
.editHttp()
.removeFromPaths(pathToDelete.get())
.endHttp()
.endRule()
.endSpec()
.done();
LOGGER.info("Deleted ingress routing " + pathToDelete.toString());
当我查看日志时,可以看到它找到了路径并输出:
已删除入口路由 可选[HTTPIngressPath(backend = IngressBackend(serviceName = my-service-6, servicePort = IntOrString(IntVal = 8080,Kind = null,StrVal = null, AdditionalProperties = {}),AdditionalProperties = {}), 路径= / myservice / 6, AdditionalProperties = {})]
但是当我描述入口时,我可以看到规则仍然存在:
Name: my-ingress
Namespace: default
Address: someAdress
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
someHost
/ admin:8888 (<none>)
/myservice/6 my-service-6:8080 (<none>)
Annotations:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Success 21m public Successfully applied ingress resource.
Warning ConfigReloadFailure 21m public Failed to apply ingress resource.
Warning ConfigReloadFailure 21m public Failed to apply ingress resource.
Warning ConfigReloadFailure 20m public Failed to apply ingress resource.
Normal Success 18m public Successfully applied ingress resource.
Normal Success 18m public Successfully applied ingress resource.
Normal Success 17m public Successfully applied ingress resource.
Normal Success 16m public Successfully applied ingress resource.
所以我的问题是:如何使用kubernetes-client-java动态删除Ingress中的路径? 我使用kubernetes-client创建了规则,所以我知道它在理论上是可行的,只是无法让它再次删除。
答案 0 :(得分:0)
您可以这样删除igress:
k8sClient.extensions().ingresses().withName("my-ingress").delete();