gpt4 book ai didi

java - 使用Java kubernetes-client从kubernetes入口删除路径

转载 作者:行者123 更新时间:2023-12-02 11:48:42 25 4
gpt4 key购买 nike

我正在尝试从入口规则中删除具有后端的路径,但无法完全正常工作。

这是我尝试删除它的方法:

// 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());

当我查看日志时,可以看到它找到了路径并输出:

Deleted ingress routing Optional[HTTPIngressPath(backend=IngressBackend(serviceName=my-service-6, servicePort=IntOrString(IntVal=8080, Kind=null, StrVal=null, additionalProperties={}), additionalProperties={}), path=/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创建了规则,因此我知道它在理论上是可行的,只是无法让它再次删除。

最佳答案

您可以这样删除igress:

k8sClient.extensions().ingresses().withName("my-ingress").delete();

关于java - 使用Java kubernetes-client从kubernetes入口删除路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50944088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com