Menu

Connecting to your Kubernetes Cluster remotely

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

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
NAME READY STATUS RESTARTS AGE
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

Conclusion

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

Tags: ,
%d bloggers like this: