Posted on 3 July 2019, updated on 21 December 2023.

As we know, kubectl is a powerful command line tool from and for Kubernetes that we are using every day. It has broad functionalities and helps us deploying Kubernetes system or some basic Kubernetes features.

Here’s are Kubernetes tips and tricks to code and deploy faster.

Kubectl autocompletion

You are going to use the command kubectl a lot. Using autocompletion will save you a lot of typing

First, install bash-completion package (which is not installed by default)

  • Linux

## Install
apt-get install bash-completion
## Bash
echo 'source <(kubectl completion bash)' >>~/.bashrc
## Zsh
source <(kubectl completion zsh)

  • Mac Os

## Install
brew install bash-completion@2

As stated in the output of brew install (“Caveats” section), add the following lines to your ~/.bashrc or ~/.bash_profile file:

export BASH_COMPLETION_COMPAT_DIR=/usr/local/etc/bash_completion.d
[[ -r /usr/local/etc/profile.d/bash_completion.sh ]] && . /usr/local/etc/profile.d/bash_completion.sh

Kubectl Aliases

One of the most useful weapons, when you start using kubectl, must be the tons of alias you can set up starting by this one

alias k='kubectl'

After adding this one, you can run into kubectl-aliases on Github. Ahmet Alp Balkan did it pretty well, you can find more about his aliases on his github

kubernetes-kubectl-aliases

Be careful, do not install kubectl alias for a newbie right away otherwise they will never understand the meaning of the commands, do it after one or two weeks of practice.

Kubernetes + Helm Charts

Helm is the best way to find, share, and use software built for Kubernetes.”
When you start running a lot of Kubernetes applications, deployments and update can be really painful, especially when you need to update the docker image’s tag before deploying. Helm Charts is a packager which helps define, install and upgrade your applications and configuration while running on your cluster by a system of release.

kubernetes-helm-cluster

A Kubernetes package is called Charts in Helm, it contains a lot of information needed to create a Kubernetes instance.

Config is the useful point there, it contains dynamic information about setting up a Chart. A Release is an existing instance on the cluster, combined with a specific Config.

Unlike apt or yum, Helms charts (package) are built atop Kubernetes and benefit from its cluster architecture. One of his main benefits is the ability to consider scalability from the start. The carts of all the images used by Helm are stored in a registry called Helm Workspace. So once deployed, your DevOps teams can easily search charts and add to their projects with ease.

You can install Helm through different methods :

  • Snap / Linux :
sudo snap install helm --classic
  • Homebrew / macOs :
brew install kubernetes-helm
  • Through script :
curl -L https://git.io/get_helm.sh | bash
  • Binary Releases :
https://github.com/helm/helm/releases
  • Initialize Helm and install Tiller on your cluster :
helm init --history-max 200
  • Then install an example chart

helm repo update
helm install --name releasemysql stable/mysql

The commands above release stable/mysql chart and the name of this release is releasemysql.

You can verify your helm release with `helm list`

  • You can finally uninstall a release

helm delete --purge releasemysql

These tips and tricks will have a significant impact on your productivity while using Kubernetes. Using less times on these will allow you to focus more on the main goal of your kubernetes applications on your cluster. After productivity comes security, learn how to create Kubernetes Secrets in this article.