Connecting to your Kubernetes Cluster remotely

Connecting to your Kubernetes Cluster remotely

(Last Updated On: September 22, 2018)

In this article we will walk through installing kubectl on a development system and configuring it to connect to a remote Kubernetes cluster.

If you do not have a Kubernetes cluster you can follow my article  CONJURING UP KUBERNETES ON UBUNTU.

Installing KUBECTL

Our first step is to install kubectl which is the command line interface to Kubernetes.  Since we are using Ubuntu we can install it easily by using SNAP.

$ sudo snap install kubectl --classic

Need Kubernetes Training?

Checkout these awesome Kubernetes courses from Pluralsight.   Pluralsight gives you outstanding training at a great price.  I use Pluralsight every time I need to learn something new.

Configuring KUBECTL

Now that we have kubectl installed we will need to configure it to connect to our remote Kubernetes cluster.  On that cluster, login and locate the .kube directory which will contain a config file.  If you followed the conjureing up kubernetes article listed in the beginning of this article, then you should have a config file named like config.conjure-canonical-kubern-0c2.  Open this file and copy all the contents.

$ ls .kube
$ cat config.conjure-canonical-kubern-0c2

Now back on your development system create a new file in the .kube directory named config-remkube.  The name isn’t important and is completely arbitrary.  You will have to edit the file and update the server IP to be the public IP of the kubernetes master or the DNS address.  If you proxied this out as stated in my earlier article then you will need to change the port to 8001.

server: http://kubernetes.admintome.lab:8001

Test The Configuration

Now everything should be configured and you can run kubectl commands by adding a kubeconfig parameter to the command:

$ kubectl get pods --kubeconfig=config-remkube
default-http-backend-gk5lb 1/1 Running 0 6d
nginx-ingress-kubernetes-worker-controller-2nk9c 1/1 Running 0 6d
nginx-ingress-kubernetes-worker-controller-dt97s 1/1 Running 0 6d
nginx-ingress-kubernetes-worker-controller-mr4c9 1/1 Running 0 6d

You can also set an environment variable so you won’t need the parameter:

$ export KUBECONFIG_SAVED=config-remkube


Using this procedure you can configure multiple connections for your different Kubernetes clusters {dev,scratch, prod, etc}.


I hope you have enjoyed this article, if so please leave a comment below.  For more articles, please signup for the AdminTome Blog below.  Also please feel free to share the article to your friends using the buttons to the left.  Thanks again for reading this post.


1 thought on “Connecting to your Kubernetes Cluster remotely

Leave a Comment

you're currently offline