Master these 3 tools for beginners and 2 tools for advanced users to stay ahead of the competition.
译自 From Zero to K8s Hero: 5 Must-Have Tools for Kubernetes,作者 Giuseppe Santoro。
In this article, we'll take a look at 5 must-have tools to help you get started on your Kubernetes journey.
The first three tools on the list are absolutely indispensable for beginners. The latter two tools can make you stand out from beginners and look like advanced users.
I'll share my views on which tools can make you stand out from your peers and which ones aren't worth learning.
What qualifies me to give such advice?
Over the past few years, I've spent countless hours trying out every Kubernetes tool I can get my hands on, both during work and in my spare time.
I have to admit that I'm a tool fanatic. I love to play around with all the shiny tools, and there are a lot of them in the Kubernetes ecosystem.
Given that new tools are popping up like mushrooms every day, I've always thought I needed some advice on which ones are worth learning and which ones aren't worth my time.
So, I tried as many tools as I could, and after years of experience, I'm now ready to mentor others.
In this article, I want to provide guidance that I was missing when I first started using Kubernetes a few years ago.
So don't waste any more time and let's dive into this article.
1. 浏览你的 Kubernetes 集群:K9s
My favorite Kubernetes tool is K9s, a terminal-based UI that lets you interact with your Kubernetes cluster.
If you're like me, you've been using "bread and... Linux", you'll appreciate the beauty of using CLI tools that are both open-source and highly customizable, with the ability to customize skins, plugins, command aliases, and custom keybindings.
What are the benefits of using K9s as the primary tool for exploring clusters:
- All standard Kubernetes objects are supported: view and interact with pods, containers, services, RBACs, volumes, events, and more.
- CRD support: Supports interaction with custom resource definitions (CRDs).
- Run Anywhere: Runs on any operating system and can be installed using most package managers.
- Skins: Change the look and feel of the UI, as well as the behavior of the UI based on the cluster and context you're working with. Among the advanced features, you can also create a read-only context to prevent any unintentional modifications in the production cluster.
- Plugin: I personally used this feature some time ago when I wanted to parse some JSON logs in a Kubernetes pod and display them in tabular form. I created a Kubectl plugin in Python that I call rich-json-logs and plugged it into K9s. Almost directly.
- Command aliases: Command aliases are not as powerful as plugins, but they can save some keystrokes.
- Custom keybindings: With just one or two keystrokes, you can view specific types of Kubernetes resources, call plugins, command aliases, or many other features.
What are the alternatives:
- Lens: A paid alternative that offers a generous free personal plan. This desktop app doesn't offer much more than K9s unless you have a very expensive Pro or Enterprise license.
- OpenLens: An open-source version of Lens. Since Mirantis, the company behind Lens, has abandoned open source, this project will no longer receive any updates.
2. 自动化一切:Kubectl
If you've ever used Kubernetes, you've probably come across Kubectl, the Kubernetes command-line tool.
Why did I only put it at the number two on my list?
This tool does everything you need to use Kubernetes, but it doesn't offer a good user experience like K9s.
When using Kubernetes, especially if you're a DevOps and in the middle of an incident, you have to act fast!
Given that I can't remember the syntax of the Kubectl commands, and that each command requires a lot of input, K9s is a better tool for my needs.
Why do I still recommend using Kubectl?
Whenever I need to write some automated scripts that interact with Kubernetes, Kubectl is my go-to tool.
The best part is that you don't need to choose between the two.
You can use K9s for speed and user experience, Kubectl for scalability, and a combination of them.
Take a look at the command below. Without using any other tools, I'll get the version tags for all pods with the tag app=cassandra.
kubectl get pods --selector=app=cassandra -o jsonpath='{.items[*].metadata.labels.version}'
I got the last command from the Kubernetes Quick Reference, which is a great resource if you want to prepare for your Certified Kubernetes Administrator exam because you can use it in the exam.
What are the alternatives:
K9s: We've already talked about this in the previous section.
Kubernetes client libraries: If you need to automatically interact with your Kubernetes cluster in your code and want to avoid using Kubectl in bash, you can use the Kubernetes SDK in the language of your choice.
3. Package Manager: Krew
The third tool on my list is Krew, which is the official package manager for Kubectl.
I only recently learned about this tool, but it's a great addition to my arsenal.
Like any package manager, there's not much to say other than that it does its job well and is supported by all operating systems.
The best part about this tool is its documentation which contains a list of official plugins that Krew supports.
If you go through the list, you may find plugins that you didn't know existed.
4. Aggregate logs from multiple Kubernetes resources: Stern
Stern is the first tool on this list for more advanced users.
If you've looked at pod logs in Kubernetes, you've probably come across a use case where you want to combine logs from different pods or containers in a pod into the same output.
[Stern] allows you to tail multiple pods on Kubernetes and multiple containers in pods. Each result is color-coded for faster debugging.
5. 查看内部:node-shell
node-shell allows you to launch a shell to access the underlying operating system of a Kubernetes node.
This tool is invaluable when developing observability tools for Kubernetes.
As I explained in my in-depth article Kubernetes: node-shell, more than once, I've had to look at Kubernetes nodes in order to keep track of pod/container logs that are written directly to node hosts to feed to Elasticsearch.
I can't do this without node-shell.
node-shell, like many of the other tools on this list, can be installed and integrated into K9s via Kreva.
conclusion
The list of tools in this article is by no means complete.
I could have mentioned:
- Helm
- Customise
- K3d
- Kind
Wait a minute.
Most of them are more advanced and worth writing a separate article.
I may cover some of them in the future.