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
HTTPProxyであるように思わカスタムリソース。Kubernetesクライアントは、型付きAPI(カスタムリソースにPOJOを提供する必要がある場合)と型なしAPI(生のハッシュマップを使用したカスタムリソースの操作)を提供します。TypelessAPIを使用してこれを行う方法の例を次に示します。
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");
}
ニーズに合ったアプローチを選択できます。興味があれば、これらのアプローチに関する私のブログを詳細にチェックしてください。
- Fabric8 Kubernetesクライアントを使用したJavaでのKubernetesカスタムリソースの処理:パート1(タイプレス)
- Fabric8 Kubernetesクライアントを使用したJavaでのKubernetesカスタムリソースの処理:パート2(型付き)