Kubernetes Fabric8 API

Sep 19 2020

현재 fabric8 API를 사용하여 POD, 서비스 등의 내용을 읽습니다.

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

API 그룹 projectcontour.io의 httpproxies에서 HTTPProxy의 내용을 검색하는 방법이 있습니까?

미리 감사드립니다 !!!

답변

1 RohanKumar Sep 20 2020 at 00:42

HTTPProxyCustom Resource 인 것 같습니다 . Kubernetes 클라이언트는 Typed API (사용자 지정 리소스에 대한 POJO를 제공해야하는 경우)와 Typeless API (원시 HashMaps를 사용 하여 사용자 지정 리소스 조작)를 제공합니다. 다음은 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. Fabric8 Kubernetes Client를 사용하여 Java에서 Kubernetes 사용자 지정 리소스 처리 : Part-1 (Typeless)
  2. Fabric8 Kubernetes Client를 사용하여 Java에서 Kubernetes 사용자 지정 리소스 처리 : Part-2 (유형화)