Aug 13, 2020

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?

  1. Verified kubectl was configured to point at a cluster
  2. Opened k9s
  3. List deployments
  4. List namespaces and select a namespace
  5. Scale a deployment
  6. List pods
  7. Sort and filter the pod list
    1. We filtered with plain text
  8. View and filter logs on a container
  9. Shell into a container
  10. Port-forward to a pod
    1. This is handy, if like me you rarely remember which port a container listens on
  11. List CRDs
  12. List instances of a CRD (storage states)
    1. 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.
  13. View YAML for a storage state
  14. Edit a storage state
  15. List and edit a config map
  16. 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!

About the Author

David Norton profile.

David Norton

Director, Platform Engineering

Passionate about continuous delivery, cloud-native architecture, DevOps, and test-driven development.Passionate about continuous delivery, cloud-native architecture, DevOps, and test-driven development.

  • Experienced in cloud infrastructure technologies such as Terraform, Kubernetes, Docker, AWS, and GCP.
  • Background heavy in enterprise JVM technologies such as Groovy, Spring, Spock, Gradle, JPA, Jenkins.
  • Focus on platform transformation, continuous delivery, building agile teams and high-scale applications.

One thought on “Explore your Kubernetes cluster with k9s

  1. Samson says:

    Thank you for taking your time and sharing the article, it is very helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Blog Posts
Using Conftest to Validate Configuration Files
Conftest is a utility within the Open Policy Agent ecosystem that helps simplify writing validation tests against configuration files. In a previous blog post, I wrote about using the Open Policy Agent utility directly to […]
SwiftGen with Image & Color Asset Catalogs
You might remember back in 2015 when iOS 9 was introduced, and we were finally given a way to manage all of our assets in one place with Asset Catalogs. A few years later, support […]
Tracking Original URL Through Authentication
If you read my other post about refreshing AWS tokens, then you probably have a use case for keeping track of the original requested resource while the user goes through authentication so you can route […]
Using Spring Beans in a Kafka Streams ExceptionHandler
There are many things to know before diving into Kafka Streams. If you haven’t already, check out these 5 things as a starting point. Bullet 2 mentions designing for exceptions. Ironically, this seems to be […]