k8s 04: kubectl

So far I used various method to deploy pod as well as to check the status of the nodes/pods. Using those method is good to know what languages the services are talking, however it is not good for the human to use directly. Because I need to know all the endpoint, the method and dialect(yaml, json), and it is not actually realistic.

In this entry, I install kubectl so that it can interpret my intention to the language that each component(basically API server) can understand, and it also shows the state in more human readable way.

As usual, the deployment image would be as follows:

Kubectl on master node

1. install kubectl
The procedure is summarised at official document “Install and Set Up kubectl“. Since I’m using ubuntu, I can use snap to install kubectl.

2. configure kubectl (not necessary)
kubectl looks for localhost by default, hence in this case I don’t really need to configure kubectl as I’m running apiserver at localhost.

3. check if it works
I can check pod status using kubectl now. Note that some of the master components are declared to be “Unhealthy”, because I have not set them up yet.

 

I have working kubectl on master node.

But you can install kubectl in your local machine so that it can talk with apiserver directly instead of using ssh to login master node. But please note it is not a good option at this point in my deployment because this environment is not configured with proper certificate, hence the conversation between your local machine and apiserver(, which most likely via the internet) would not be encrypted.

Kubectl on local machine

1. Modify apiserver configuration

By default, apiserver only listens the request from localhost. So I need to change systemd configuration so that it passes the listening ip address when the service launches.

2. Install kubectl on local machine

Follow the official document, and install kubectl on you machine. In my case, I’m using Mac, and using brew to install kubectl.

3. Configure context for remote connection

I need to configure kubectl on my local machine so that it looks for the remote apiserver. Because I’m using GCE on GCP, I use the external ip of the instance in the “server” option here.  

4. Check it works

Once configured, I can use kubectl from local machine just the same as the master node.