Kubernetes Fabric8 API

Kubernetes Fabric8 API

我目前使用 fabric8 API 来读取 PODs、服务等的内容

KubernetesClient client = new DefaultKubernetesClient();
client.configMaps().withName("ConfigMapName");

有没有办法从 api 组 projectcontour.io 的 httpproxies 中检索 HTTPProxy 的内容?

提前致谢!!!

HTTPProxy 似乎是 Custom Resource. Kubernetes Client provides a Typed API (where you need to provide POJOs for your Custom Resource) and a Typeless API(使用原始 HashMap 处理自定义资源)。这是一个关于如何使用 Typeless API:

执行此操作的示例
try (KubernetesClient client = new DefaultKubernetesClient()) {
    CustomResourceDefinitionContext httpProxyContext = new CustomResourceDefinitionContext.Builder()
            .withGroup("projectcontour.io") // <-  Group of Custom Resource
            .withVersion("v1")              // <-  Version of Custom Resource
            .withPlural("httpproxies")      // <-  Plural form as specified in CRD
            .withScope("Namespaced")        // <-  Whether Custom Resource is Cluster Scoped or Namespaced
            .build();

    // List all HTTPProxies
    Map<String, Object> httpProxyList = client.customResource(httpProxyContext).list("ns1");
    // Get a specific HTTPProxy
    Map<String, Object> myHttpProxy = client.customResource(httpProxyContext).get("ns1", "tls-example");
}

您可以选择您认为适合您需要的任何方法。如果有兴趣,您可以详细查看我关于这些方法的博客:

  1. Handling Kubernetes Custom Resources in Java using Fabric8 Kubernetes Client: Part-1(Typeless)
  2. Handling Kubernetes Custom Resources in Java using Fabric8 Kubernetes Client: Part-2(Typed)