DEV Community

Michael Cade
Michael Cade

Posted on • Originally published at vzilla.co.uk on

The vZilla Kubernetes tools, tips & tricks

This week saw a lot of useful procrastination mostly around different tools to make your day-to-day experience with Kubernetes that little more easier or possibly more exciting. I put together this twitter thread but as with anything on twitter the life span of that thread is gone within minutes so I wanted to document my Kubernetes tips and tricks here as well.

https://twitter.com/MichaelCade1/status/1427928444629831680?s=20

Tips for Kubernetes: 1 – kubectl explain

Have you been looking for the man pages for Kubernetes? (man, page is short for manual page) or could also be classed as documentation.

Get documentation of various resources. For instance, pods, nodes, services, etc.

082021 1643 ThevZillaKu1

Tips for Kubernetes: 2 – Autocompletion

Why would you want to remember every single full command that you ever need to run, why not use autocompletion, this is a simple line of code to be added to your .bashrc or .zshrc file and it gives you that next command or at least a hint on where you might want to go.

082021 1643 ThevZillaKu2

Tips for Kubernetes: 3 – Aliases

Aliases, who wants to be writing kubectl in every time you need to find something else, the simple way to fix this is with an alias, but you could also get creative with other aliases here and add more simplified ways to submit commands. I have started very minimal with just k = kubectl but some people have gone and written what looks to be their own language through aliases.

Here are some solid examples you might want to also try – https://github.com/ahmetb/kubectl-aliases

082021 1643 ThevZillaKu3

Tips for Kubernetes: 4 – kubectx

I don’t know about you but switching contexts takes a few seconds longer when you must do it the manual way, the kubectl config get-contexts to find the context name you want and then kubectl config use-context to switch is a pain, when you have kubectx you have a real easy way of switching between the contexts. There are some other tools out there later as well.

082021 1643 ThevZillaKu4

Tips for Kubernetes: 5 – Generate YAML files with kubectl

Everything you are doing within your Kubernetes should be based on code, but what if you do make changes in the middle of testing, well with the following command you can export your YAML manifest and make sure your source code is up to date with what you have in your cluster or so you can share the latest with others.

kubectl create deployment nginx –image nginx –dry-run=client -o yaml > deployment.yaml

082021 1643 ThevZillaKu5

https://twitter.com/florian_casse made a good point here or an added point with

082021 1643 ThevZillaKu6

Tips for Kubernetes: 6 – Validate your changes

Ever wanted a way to confirm the changes you are making to your YAML files before applying them to your cluster? Or to see what has changed between? You can see the + and – on the left side of the terminal indicating the differences between the live system and your changes to the YAML file.

kubectl diff deployment.yaml

082021 1643 ThevZillaKu7

082021 1643 ThevZillaKu8

Tips for Kubernetes: 7 – Monitoring Hardware Resources

Want to understand what your CPU and Memory looks like and broken down into different Kubernetes resources, find out with these commands

kubectl top nodes

kubectl top pod –all-namespaces

082021 1643 ThevZillaKu9

Tips for Kubernetes: 8 – Changing Colours

This one was added by Florian again on the twitter thread, but this allows you colorise the output of kubectl.

https://t.co/klj2p2codU?amp=1

082021 1643 ThevZillaKu10

Then is where the procrastination came in because I found some more useful or at least that look to be useful for day to day tasks, I am going to list them quickly here but I intend to use these and update the post with hopefully more.

kubens – https://github.com/ahmetb/kubectx/blob/master/kubens – like changing those contexts this allows you to switch to namespaces and stay switched there so you don’t have to add the -n and namespace name every time you want to find out something.

arkade- I have mentioned this before in another blog but you can find more information here, https://github.com/alexellis/arkade I do in fact use this handy little tool to get my clis and other tools.

I think another huge topic we could raise here is kubectl plugins themselves, and this is where I spent most of my day yesterday procrastinating and then even taking the kubestr binary and making that a kubectl plugin. To name a few though here for everyone to go and see if they work for you:

Krew – first and foremost krew is a plugin installer, over 100 plugins available it seems to be like arkade in that it gives you a nice central way to install multiple plugins and it’s a plugin itself.

Then we have a few more that I am not going to describe but leave them here for you to explore and we will try and do another blog soon covering their use cases and why.

  • Access-matrix
  • Whoami
  • Neat
  • View-allocations
  • View-utilisation
  • Who-can
  • Resource-capacity
  • Tree

I hope this post was useful but more importantly I would love to add your favourite tips, tricks and tools if not mentioned here,

Top comments (0)