Cluster Management and Commands

Cluster Management and CommandsKubectl ContextsChecking Cluster ConnectionUsing kubectlNamespacesSwitching Contexts


Our cluster runs remotely on Amazon EKS cloud infrastructure. The easiest way to communicate with it from your local machine is through the kubectl command line utility.

The cluster is separated into three main namespaces: production, staging and default.1 Each namespace functions like a separate virtual cluster, using the same hardware resources. The purposes of the first two are pretty self-explanatory; the last is a general testing ground.

img

This section gives a quick summary of some useful setup steps.

 

Kubectl Contexts

Whenever you're using kubectl, it will have an active context. A context is the combination of:

 

Checking Cluster Connection

You can check that you're talking to the right cluster with:

kubectl config current-context
arn:aws:eks:ap-southeast-1:238288103121:cluster/scratch-cluster

And make sure you're connected with:

kubectl get pods -n default
Name Ready Status Restarts Age
hello-node-5776cf4bcf-4sjrt 1/1 Running 0 3s

 

Using kubectl

There's plenty of articles introducing kubectl, so I'll mostly skip that and just give the necessary command for a situation. That said, I recommend:

 

Namespaces

Pretty much all objects except for Nodes are specific to a namespace. In order to access them, you'll need to be in the right namespace. Objects in different namespaces can have the same names, so you need to be careful with this one. Your active context is always associated with a namespace, which all your commands will be run in automatically.

You can check the current active namespace on Mac with:

kubectl config view | grep namespace
   namespace: staging

on Windows:

kubectl config view | findstr namespace
   namespace: staging

You can change the current context namespace with:

kubectl config set-context --current --namespace=NAMESPACE
Context "arn:aws:eks:ap-southeast-1:238288103121:cluster/scratch-cluster" modified.

You can run a kubectl command in a different namespace than the current context using the -n flag. For example:

kubectl get pods -n default
Name Ready Status Restarts Age
hello-node-5776cf4bcf-4sjrt 1/1 Running 0 3s

vs:

kubectl get pods -n staging
Name Ready Status Restarts Age
converter-54dd9668b6-lvhc8 1/1 Running 0 23d
graphql-77bf76b879-qkbf7 1/1 Running 0 20m
ui-cddc5db5d-tw2wd 1/1 Running 0 23d
...

 

Switching Contexts

Do you have a different cluster you want to talk to? Then you'll need to change the active context. This will be the case if you want to play around with minikube at all, for example.

To see available contexts, use:

kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* arn:.../clustername arn:.../clustername arn:.../clustername default
minikube minikube minikube

This will let you see the contexts available to you. To switch contexts, you'll need their name from the NAME column:

kubectl config use-context NAME
Switched to context "minikube".

You can switch back in the same way. If you want to change any of the names, you can edit the ~/.kube/config file directly.

 

 


 

 

 


1 There are some other namespaces in the cluster which you might run into, like prometheus and kube-system. These are for monitoring and administrating the cluster.