Six tools to Simplify Kubernetes Journey - Day 3?-?Kubernetes Terminal Dashboard k9s
Reference https://k9scli.io/

Six tools to Simplify Kubernetes Journey - Day 3?-?Kubernetes Terminal Dashboard k9s

What is k9s?

As per official documentation?K9s?is a terminal-based UI to interact with your Kubernetes clusters. K9s is an open-source project and is written in GO language. The way it works, it continuously monitors your Kubernetes cluster for any changes and provides a shortcut command to interact with Kubernetes resources.

Installing

Installation of K9s is pretty straightforward, and binaries for various distribution are available on the?release page.

# Download the binaries(In this use case Linux)
wget https://github.com/derailed/k9s/releases/download/v0.24.15/k9s_Darwin_x86_64.tar.gz

# Move it to the desired path
sudo cp k9s /usr/local/bin

#Change the permission
sudo chmod +x /usr/local/bin/k9s        

Start using k9s

To start using k9s, execute the k9s command on your console. It will use the standard kubeconfig file(~/.kube/config) same as kubectl.?

k9s

No alt text provided for this image

As you can see, this is showing the default pod running in the default namespace. This is equivalent of

kubectl get pod

kubectl get pod

  • To see all the pod in all namespaces (press 0). This is equivalent of

kubectl get pod -A

No alt text provided for this image

  • If you are looking for a specific pod for e.g., kube-proxy, there is a search mode to do that. Type / followed the resource you are searching (/kube-proxy)

No alt text provided for this image

  • Similarly, if you want to perform a search based on labels, type -l followed by the name of the label(-l app=nginx)

No alt text provided for this image

  • To go back to the default namespace(press 1)

Note:?This dashboard refreshes itself every 2 sec. To modify the default configuration, modify the k9s configuration file.

K9s configuration file

~/.k9s/config.yml        

For e.g., To modify the default k9s refresh interval, edit the config file and change the refreshRate to the desired value.

cat ~/.k9s/config.yml
k9s

refreshRate: 2:        

  • To check all the replicaset running in your cluster, type colon followed by rs(:rs). This is similar to kubectl get rs

No alt text provided for this image

Note:?In case if you want to rollback to the previous version, type ctrl+l.

  • Now to check all the deployment running in your cluster type colon followed by deploy(:deploy) and then enter.

No alt text provided for this image

  • Now to get all configmap, press: followed by cm(:cm)(This is similar to kubectl get cm)

No alt text provided for this image

Now select the configmap and then press u to get the list of resources that use it.

No alt text provided for this image

  • Some other useful commands

:svc - Services(equivalent kubectl command: kubectl get svc

:ns - namespaces(equivalent kubectl command: kubectl get ns)

:ing - ingress(equivalent kubectl command: kubectl get ingress))        

  • To get the complete help of all the commands just type ?

No alt text provided for this image

  • press d for describe(equivalent kubectl command: kubectl describe pod <pod name>.

No alt text provided for this image

  • Press l for logs(equivalent kubectl command: kubectl logs <pod name>). To select the time range to display these logs.

No alt text provided for this image
0: for the entire lifecycle of the po

1: last 1 min

2: last 5 min

3: last 15 min

4: last 30 min

5: last 1 hourd        

  • press y for yaml(equivalent kubectl command: kubectl get pod <pod name> -o yaml).

No alt text provided for this image

  • If you want to save the output of the yaml manifest file, press ctrl + s. As you can see at the bottom of the screen, it’s storing the output in?/tmp/k9s-screens-prashant/kind-my-test-cluster/YAML-1612243106814649920.yml file).

No alt text provided for this image

  • This is one of the most common debugging practices where you save the output of your manifest to a file, modify it(by fixing the issue or add some configuration) and then apply it. If you want to follow the same practice using k9s type :dir and then the location where you save the manifests(:dir /tmp). Drill down till you reach the location where manifest is saved(/tmp/k9s-screens-prashant/kind-my-test-cluster/YAML-1612243106814649920.yml), and to apply that configuration, press a(a for apply).

No alt text provided for this image

  • press e to edit the deployments(equivalent kubectl command: kubectl edit pod <pod name>)

No alt text provided for this image

  • NOTE: This will open the text editor based on your environment variable(to set vim as the default editor export EDITOR=vim)
  • ctrl +d to delete the resource (equivalent kubectl command: kubectl delete pod <pod name>)

No alt text provided for this image

  • ctrl + k to kill the resource or forceful deletion(equivalent kubectl command: kubectl delete pod <pod name> — force — grace-period=0)
  • To get the shell access press s (equivalent kubectl command: kubectl exec -it nginx-6799fc88d8-wpq7w --sh)

No alt text provided for this image

  • If you want to switch to a particular context type?: followed by ctx(:ctx)

No alt text provided for this image

  • If you want to dig into your cluster resources and see it dependencies, type?:xray followed by a resource(:xray pod)

No alt text provided for this image

  • If you want to see the entire state of your cluster with the help of the dashboard, then type a colon followed by pulse(:pulse).

No alt text provided for this image

  • Another useful feature provided by k9s is called Popeye. Popeye is a great analysis tool. It performs the resource scan and gives your report about any misconfiguration or operation issues. Some common errors reported by Popeye are container running as root, missing probes, and resource limits.

No alt text provided for this image


  • If you further drill down by just typing an enter, you will see something like this.

No alt text provided for this image

  • k9s also support basic helm command; e.g., you can run

helm repo list or helm list        

Alternative Tools

The other alternative solutions are

  • Lens: https://k8slens.dev/?
  • Kubernetes Dashboard: https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/

I have used Lens in the past and liked it. It has a friendly UI; we can easily switch between multiple contexts and clusters; the only drawback is that it slows the system.?

No alt text provided for this image

Wrapping Up

K9s comes with a lot of handy features and shortcuts, which is easy to work with. I love this tool as I now don't need to type the lengthy kubectl command. It also supports features like custom?plugins?and?benchmark(using Hey), which I still need to explore. If you like any feature or believe a K9s feature is missing in the blog, please post in the comment section.
















要查看或添加评论,请登录

Prashant Lakhera的更多文章

社区洞察

其他会员也浏览了