简体   繁体   English

使用 java 客户端从 Kubernetes 命名空间中删除轮廓 httpproxy

[英]Deleting contour httpproxy from Kubernetes namespace using java client

I am working on the K8s implementation using kubernetes java client.我正在使用 kubernetes java 客户端进行 K8s 实现。 I am looking for the solution to delete Contour HTTPProxy which are in invalid state.我正在寻找删除处于无效状态的Contour HTTPProxy的解决方案。 However I am not able to figure out how to do it with help of Java Client.但是,我无法在 Java 客户端的帮助下弄清楚如何做到这一点。

I am aware that we can delete the ingress using below code我知道我们可以使用以下代码删除入口

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

Any help on how to delete Contour HTTPProxy object from K8s namespace using java client will be appreciated?关于如何使用 Java 客户端从 K8s 命名空间中删除 Contour HTTPProxy 对象的任何帮助将不胜感激?

Contour HTTPProxy seems to be a custom resource . Contour HTTPProxy 似乎是一个自定义资源 You can either use our typed(required CustomResource POJOs) or typeless API(CustomResource manipulation using raw maps) for deleting HTTPProxy.您可以使用我们的类型化(必需的 CustomResource POJO)无类型 API(使用原始映射的自定义资源操作)来删除 HTTPProxy。

Here is an example of doing it using the typeless API(based on KubernetesClient v5.4.1):这是使用无类型 API(基于 KubernetesClient v5.4.1)执行此操作的示例:

try (KubernetesClient client = new DefaultKubernetesClient()) {
    CustomResourceDefinitionContext context = new CustomResourceDefinitionContext.Builder()
            .withKind("HTTPProxy")
            .withPlural("httpproxies")
            .withGroup("projectcontour.io")
            .withVersion("v1")
            .withScope("Namespaced")
            .build();

    boolean isDeleted = client.customResource(context).inNamespace("default").withName("root").delete();
    if (!isDeleted) {
        logger.warn("Unable to Delete HTTPProxy {} in {} namespace", "root", "default");
    }
    logger.info("HTTPProxy {} successfully deleted.", "root");
} catch (KubernetesClientException exception) {
    logger.error("Exception in interacting with Kubernetes API", exception);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM