Thursday, 29 July 2021

Accessing Remote Kubernetes server using the Kubectl

Below are the configuration required to make the kubectl, access the K8s running in a remote server. So Searched through the documentation and found the following good solution that is 100% working.


"This Post does not require any certificate or key to access the remote k8s."


Below are the syntax given by the K8s Documentation. 


Syntax:


kubectl config set-cluster default-cluster --server=https://<host ip>:6443 --certificate-authority <path-to-kubernetes-ca> --embed-certs


kubectl config set-credentials <credential-name> --client-key <path-to-key>.pem --client-certificate <path-to-cert>.pem --embed-certs


kubectl config set-context default-system --cluster default-cluster --user <credential-name>


kubectl config use-context default-system


Exmples:


kubectl config set-cluster my-cluster --server=https://1.2.3.4 --insecure-skip-tls-verify=true


kubectl config set-credentials my-credentials [--token=bearer_token] or [--username=username] [--password=password]


In My case it was token. hence I used Token you can use the username and password also.


kubectl config set-context my-system --cluster my-cluster --user my-credentials --namespace=default


kubectl config use-context my-system


After making these changes the context will be switched to the my-system. then when you execute the kubectl it will give results from the remote k8s. In case you need to switch. Use the below command to switch to local or other remote repositories. This information will be available in the .kube/config file. To Access go to Run (win+R) and type .kube and hit enter here you can see this file.


kubectl config use-context my-system


Happy Learning !!!!

No comments:
Write comments