Kubernetes is one of the greatest revelations in container technology of recent years. For any company looking to create large-scale and widely-available containers, Kubernetes is a great feature-rich and easy to use option. Even for those who have been won over to the applications of Kubernetes, there are still some underused features that will amplify your experience and help you make the most of this invaluable technology. Here are some Kubernetes Tips and Tricks.

Recommended Read: Understanding Kubernetes etcd

Also Read: The (in)complete Guide To DOCKER FOR LINUX

Kubernetes Tips & Tricks

Let Bash Do The Work For You

Perhaps the simplest but most effective command in your arsenal is using bash to autocomplete your kubectl commands. This opening the shell for any long entries (for example, “-all-namespaces”), the .bashrc will begin completing them for you. Enter the following command line to add autocomplete:

$ echo “source <(kubectl completion bash)” >> ~/.bashrc


Cleaning Up After You

Another handy automation tip is to use a command to clean up docker images. You’ve probably noticed this feature is already set as a default: once 90% capacity has been reached on the docker, or on the var or lib, the contents is automatically cleared. However, you may find (especially is you’re using a version of Kubernetes before 1.7) that the inode threshold lacks a default setting, meaning that you could have spent all your inodes with only half of your disk space filled. To avoid this scenario if you’re using Kubernetes 1.4 to 1.6, enter this command:




Pushing To The Limits

Speaking of which, you can also set defaults for memory and CPU limits in Kubernetes namespaces. This is a failsafe to avoid memory leaks from open connections: anyone can make this mistake, it’s just about having a backup if you do. The default limit works on an individual namespace basis, but the following command will cap out the memory at 512Mi if no other limit is set:

apiVersion: v1  

 kind: LimitRange  


   name: mem-limit-range  



   - default:  

       memory: 512Mi  


       memory: 256Mi  

     type: Container


Localizing Your Clusters

The Minikube function is so simple it barely needs a full point. It helps you run Kubernetes clusters locally, meaning you can build and run applications right on your own computer. It’s as simple as running:

$ minikube start

If, however, you want your images pushed by your docker build to a local cluster, run this command:

$ eval $(minikube docker-env)


Restricting Access

This one is not a command but general advice for using Kubernetes. The temptation with any technology is to let everyone have a go, give access to all team members so they can all contribute to deploying clusters. However, giving all team members complete access can lead to a lot of ad hoc actions if all team members have access to create and delete, so it might be more practical to divide teams by namespaces and assign admins who can monitor cluster deployment.


Label Everything

Labels are one of the core elements of Kubernetes, but their value bears repeating. Labels are there to connect one object or element to another in a loose, less commanding way, aiding with team organization, project management, and queries. You can even use labels to subdivide one cluster into multiple mini-environments. If, for example, you have one cluster achieving two functions, labels can divide selection so that the same function has two endpoints, depending on the query intention.

Labels are particularly powerful on Kubernetes Go, a useful little client that’s highly customizable. As the name suggests, this client has its origins in GO, and it’s suitable for everything from deployment engines to clean-up applications.


Pod Disruption Budgets (PDB)

This feature is invaluable for making sure your app avoids any downtime, like a refreshing morning shower for your systems. Any deployment with more than 1 instance is not complete without a Pod Disruption Budget to drain nodes and update clusters. Added by yaml and making use of label selectors, a PDB is there for you in any cases of voluntary disruption. Here’s an example of a PDB:

apiVersion: policy/v1beta1  

 kind: PodDisruptionBudget  


   name: app-a-pdb  


   minAvailable: 2  



         app: app-a

Keep an eye on minAvailable and matchLabels: these elements let you control your concurrently running instances. Add to your minAvailable to drain more Nodes and to your matchLabels to multiple deployments. So these were some of the Kubernetes Tips & Tricks, please do also share your tips & tricks using the comment box below.

Beatrix Potter works as a tech blogger at Academic writing service. She specializes in container technology, including Docker and Kubernetes, but also writes about web development and app building. She also likes baking sourdough bread and knitting.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter

Linux TechLab is thankful for your continued support.