You MUST use these 6 Kubernetes Tools!!! (kubectx, kubens, kube-ps1, k9s, popeye, stern) - read the full article about Kubernetes tutorial, IT Consulting and from Anton Putra on Qualified.One
Kubernetes comes with a prepackaged kubectl tool that is suitable for basic operations.
A Kubernetes community built a lot of tools around the project to simplify our lives and improve monitoring and management of the Kubernetes clusters.
Lets go over the most existing tools that I use in day-to-day life.
You often have to deal with multiple Kubernetes clusters in your environments, even if its just staging and production clusters.
You need to switch context between them frequently.
Kubectl comes with the command to switch clusters, for example, "kubectl config use-context minikube" in that case, you need to know the exact context name to switch.
The first tool was built to simplify that.
kubectx helps you switch between clusters back and forth.
If you are using zsh, you will be able to type kubectx and switch between clusters using up and down arrows.
If you are not using zsh, when you type kubectx, you get a list of available clusters, and then you can pick one and type kubectx and the name of cluster and press enter.
For example, here, I switch to the EKS context.
This project comes with another very helpful tool that I use all the time.
Its called kubens.
Similar to kubectx, kubens allows you to switch between namespaces.
Lets quickly get all the namespaces in my EKS cluster.
We have a few of them, including api namespace.
Now, suppose I want to get pods in that namespace or even any type of resource such as deployment, statefulset, or even custom resource definition.
In that case, I always need a namespace flag.
Its very annoying sometimes.
Now you can use kubens and switch to that namespace.
You can select it from the menu or use kubens and then provide the namespace.
The active namespace is api.
Now just run kubectl get pods without -n flag, and you get pods in api namespace.
Now you know how to switch between Kubernetes clusters and namespaces quickly.
But if you come back tomorrow, would you remember the active context or namespace? Of course not, and you would run the same kubectx or kubens commands just to check where you are right now.
The following tool is used to show your current context and a namespace right in the terminal.
Its called kube-ps1: Kubernetes prompt for bash and zsh.
When you activate that plugin, you will get the current context which is EKS right now, and the namespace api.
Lets switch to the default namespace.
And also, lets switch to a different context.
Now were in the minikube Kubernetes cluster and default namespace.
Next is one of the most popular tools built around Kubernetes.
Its called k9s.
Its a VIM-like cli to manage your Kubernetes clusters.
The aim of that project is to make it easier to navigate, observe and manage your applications in the wild.
Lets run it.
We are in minikube clsuter, we can see the verion of the kubetnets and k9s.
Lets switch to the EKS context.
Like in VIM, you can type a colon and then provide a command.
In this case, ctx.
Then select the one you want to use using up and down arrows and press enter.
If you have a metrics server installed, k9s will show you the cluster CPU and memory utilization.
By default, it will list pods in the active namespace.
Lets see what we can do here; Ill just give you a small subset of what you can do with k9s.
You can switch between namespaces using numbers, for example, 0 for all namespaces, 1 for api namespace 2 default, etc.
You can get logs right from here; just select the pod and press l.
You can ssh to the pods; same here select the target and press s.
You can delete the object by using the ctrl d combination.
To switch between Kubernetes objects, type colon, and the type, for example, deployment.
We have a single express deployment in api namespace.
You can describe the objects using the d letter.
Or you can even edit by typing e.
Lets increase the replica count from 3 to 4.
If you type svc, youll get Kubernetes services, and the same applies to all objects.
The next tool is Popeye - A Kubernetes Cluster Sanitizer.
Popeye is a utility that scans live Kubernetes clusters and reports potential issues with deployed resources and configurations.
If you run just popeye, it will generate a report right in the terminal.
You can save it in HTML and open it with a browser.
Lets run it.
On the top, youll see a score; we have A. We have errors, warnings, and Info.
Now lets introduce the mistake.
Lets break the service by pointing to a non-existing port number.
We have container port 8081, and in the service, we point to 8080, which may take some time to debug.
But if we reran our tool, we will get that error immediately.
Lets apply the service first.
Now instead of A, we got B, which means we have errors.
Lets scroll to find out.
Here is the error, no target port matches the service port since it must be 8081 and not 8080.
Now we can fix that.
The last tool is stern.
Stern allows you to tail multiple pods on Kubernetes and multiple containers within the pod.
Each result is color-coded for quicker debugging.
Lets get pods in api namespace; we have 4 of them.
If you just run stern and the pod name express, it will show you logs from each pod with a different color.
You can use a selector; there are different options that you supply to grab logs from the pods in your cluster.
Alright, thats the list of the tools that I use all the time.
Thank you for watching, and Ill see you in the next video.
Anton Putra: You MUST use these 6 Kubernetes Tools!!! (kubectx, kubens, kube-ps1, k9s, popeye, stern) - IT Consulting