How to use Kubernetes Java Client
my kubernetes master and slave in the host :192.168.1.182, use the secure port 6443. my java project in 192.168.1.106,
ApiClient client = Config.fromUrl("https://192.168.1.182:6443");
client.setSslCaCert(new FileInputStream("ca.pem")); // this is a right pem
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api();
V1NamespaceList namespaceList= api.listNamespace(null,null,null,null,null,null, null, null, null);
but it's error
io.kubernetes.client.ApiException: Unauthorized
at io.kubernetes.client.ApiClient.handleResponse(ApiClient.java:882)
at io.kubernetes.client.ApiClient.execute(ApiClient.java:798)
at io.kubernetes.client.apis.CoreV1Api.listNamespaceWithHttpInfo(CoreV1Api.java:15606)
at io.kubernetes.client.apis.CoreV1Api.listNamespace(CoreV1Api.java:15584)
I wannt to ask ,how to use Kubernetes Java Client when the port of apiserver is 6443?
you need token.
kubectl describe secrets admin-token-xxx --namespace kube-system
you can get token
Do you have a valid Kubeconfig file?
If you do (and it is in ${KUBECONFIG} or ${HOME}/.config/kube) then
Config.defaultClient();
Will just load it for you.
If not and you are constructing the client in code, then you need to add a token, or a certificate to the config in order to identify yourself, depending on how authentication is setup for your cluster.