Explore your Kubernetes cluster with k9s
If you use Kubernetes, you have probably become adept at crafting commands with kubectl (pronounced “koob-cuddle”). Sure, we prefer to interact with the cluster with declarative configs via a deployment pipeline, but sometimes you need to see what’s going on, right now. Cue the commands, something such as…
$ kubectl config set-context --current --namespace=transaction-api Context "gke_davidnortonjr_us-central1-c_cluster-1" modified $ kubectl get pod -o wide … $ kubectl describe $ kubectl logs error: a container name must be specified for pod xxx-yyyy, choose one of: [event-exporter prometheus-to-sd-exporter] $ kubectl logs lots and lots of verbose logs $ kubectl exec -it -c container name
And so on. kubectl is great and all, but it can get a little wordy. It’s a powerful tool that every person that works with Kubernetes should master. But folks, you should really check out k9s.
k9s is a cross between kubectl and the Kubernetes dashboard. It is command-line based, but with an interactive “curses” UI. You can install the binary anywhere you can install kubectl, and it uses the same configuration and authentication mechanisms. And it is just so great! But don’t take my word for it, check out this short screencast:
What did we just do here?
- Verified kubectl was configured to point at a cluster
- Opened k9s
- List deployments
- List namespaces and select a namespace
- Scale a deployment
- List pods
- Sort and filter the pod list
- We filtered with plain text
- View and filter logs on a container
- Shell into a container
- Port-forward to a pod
- This is handy, if like me you rarely remember which port a container listens on
- List CRDs
- List instances of a CRD (storage states)
- To me, this is a real cool part. k9s wasn’t coded to know anything about these custom resource definitions – but the Kubernetes API is extensible and self-describing, so it was able to learn about it and would display any custom columns, as well.
- View YAML for a storage state
- Edit a storage state
- List and edit a config map
- List, view, and decode a secret
k9s is a powerful tool that makes it easy to quickly get done what you need to get done in Kubernetes!
One thought on “Explore your Kubernetes cluster with k9s”
Thank you for taking your time and sharing the article, it is very helpful.