How to connect to Alibaba Cloud cluster use kubeconfig How to connect to Alibaba Cloud cluster use kubeconfig kubernetes kubernetes

How to connect to Alibaba Cloud cluster use kubeconfig


If you created a cluster using kubeadm for example, you will need to enter the instance through SSH and download the kube-apiserver client certificates and CA from /etc/kubernetes/pki.

Once you have them, you can add the configuration to kubeconfig using these commands (based on https://github.com/kelseyhightower/kubernetes-the-hard-way/blob/master/docs/10-configuring-kubectl.md). Make sure you replace the IP_ADDRESS_OF_YOUR_CLUSTER, CLIENT_CERTIFICATE, CLIENT_KEY placeholders (instead of admin you can choose another name for the credentials):

kubectl config set-cluster your cluster \  --certificate-authority=CA_CERTIFICATE \  --embed-certs=true \  --server=https://IP_ADDRESS_OF_YOUR_CLUSTER:6443kubectl config set-credentials admin \  --client-certificate=CLIENT_CERTIFICATE \  --client-key=CLIENT_KEYkubectl config set-context your-cluster-context \  --cluster=your-cluster \  --user=admin

If you get authentication errors, then you used the incorrect certificates.

In addition, make sure that you open port 6443 in your cloud firewall, otherwise you will not be able to access.