Can create Kongingress by k8s CRD api

In my case ,i want use java api to create kongingress ,find a lot of things , i got k8s provide crd module to get&create crd.
I use CustomObjectsApi.listClusterCustomObject get kongingress config ,but when i use CustomObjectsApi.createClusterCustomObject api, k8s return 404 not found ;
Is my code wrong or is need setting some config


get kongingress code :
CustomObjectsApi apiInstance = new CustomObjectsApi();
String group = “configuration.konghq.com”;
String version = “v1”;
String plural = “kongingresses”;
String pretty = “ture”;
String fieldSelector = “metadata.namespace=” + buId;
try {
Object result = apiInstance.listClusterCustomObject(group, version, plural, null,
null, fieldSelector, null, null,
null, null, null);
String listCluster = JSONObject.toJSONString(result);
log.error(listCluster);
JSONObject jsonObject = JSONObject.parseObject(listCluster);
if (null == jsonObject.getJSONArray(“items”) || jsonObject.getJSONArray(“items”).isEmpty()) {
return false;
} else {
return true;
}
} catch (Exception e) {
log.error(“Get KongIngress error,” + buId, e);
throw new RuntimeException(“Get KongIngress error,” + buId, e);
}

return message:
{“apiVersion”:“configuration.konghq.com/v1",“items”:[],“kind”:“KongIngressList”,“metadata”:{“continue”:"",“resourceVersion”:“694409337”,“selfLink”:"/apis/configuration.konghq.com/v1/kongingresses”}}


create kongingress code :
CustomObjectsApi apiInstance = new CustomObjectsApi();
String group = “configuration.konghq.com”;
String version = “v1”;
String plural = “kongingresses”;
Object createRs = apiInstance.createClusterCustomObject(group, version, plural, ingressYaml, null, null,
null);

ingressYaml like:
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
name: https-only
namespace: testbu001
route:
protocols:

  • https
    https_redirect_status_code: 302

error message:
io.kubernetes.client.openapi.ApiException: Not Found
at io.kubernetes.client.openapi.ApiClient.handleResponse(ApiClient.java:971)
at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:883)
at io.kubernetes.client.openapi.apis.CustomObjectsApi.createClusterCustomObjectWithHttpInfo(CustomObjectsApi.java:263)
at io.kubernetes.client.openapi.apis.CustomObjectsApi.createClusterCustomObject(CustomObjectsApi.java:218)

We unfortunately aren’t able to help you write a Java application to do this or assist with using the Kubernetes client libraries, but in general, yes, this should be possible: if you’ve installed our CRDs into your cluster, a Kubernetes API client issuing a well-formed request to the API server should be able to create a KongIngress resource.

That “Not Found” error likely indicates that you either haven’t actually installed the KongIngress CRD (and the API server doesn’t recognize attempts to create those resources) or that the client’s API server location setting isn’t correct (it’s sending an HTTP request to some other HTTP server, which doesn’t recognize the Kubernetes API routes and returns a 404).


© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ