Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure kubectl command to access remote kubernetes cluster on azure

I have a kubernetes cluster running on azure. What is the way to access the cluster from local kubectl command. I referred to here but on the kubernetes master node there is no kube config file. Also, kubectl config view results in

apiVersion: v1 clusters: [] contexts: [] current-context: "" kind: Config preferences: {} users: [] 
like image 293
Phagun Baya Avatar asked Mar 30 '16 11:03

Phagun Baya


People also ask

How do I access Kubernetes cluster remotely?

Go client. To get the library, run the following command: go get k8s.io/client-go@kubernetes-<kubernetes-version-number> , see INSTALL.md for detailed installation instructions. See https://github.com/kubernetes/client-go to see which versions are supported. Write an application atop of the client-go clients.

How do I access Azure Kubernetes cluster?

To access your AKS cluster, navigate to the Microsoft Azure Portal and select the “Kubernetes services” section. Click the name of the cluster you want to access. Then, click “View Kubernetes dashboard”. Once you have executed the commands above, the Kubernetes dashboard IP address will be displayed.


1 Answers

Found a way to access remote kubernetes cluster without ssh'ing to one of the nodes in cluster. You need to edit ~/.kube/config file as below :

apiVersion: v1  clusters:     - cluster:     server: http://<master-ip>:<port>   name: test  contexts: - context:     cluster: test     user: test   name: test 

Then set context by executing:

kubectl config use-context test 

After this you should be able to interact with the cluster.

Note : To add certification and key use following link : http://kubernetes.io/docs/user-guide/kubeconfig-file/

Alternately, you can also try following command

kubectl config set-cluster test-cluster --server=http://<master-ip>:<port> --api-version=v1 kubectl config use-context test-cluster 
like image 141
Phagun Baya Avatar answered Oct 17 '22 07:10

Phagun Baya