Top 10 Kubernetes Tips and Tricks You Should Know

Recently we’ve covered a topic on top Kubernetes myths and facts that is helpful for you to understand the spreaded Kubernetes myths and the facts behind them. In this article, we will discuss about top Kubernetes tips and tricks. It will help you to make Kubernetes usage easier.

The most significant technological revolution is the introduction of container technology. As a result, Kubernetes orchestration system gained popularity in recent times. Kubernetes is an open-source ecosystem which helps in automation of deployment, scaling, and management for containerized applications. The following discussion would reflect on helpful Kubernetes tips to help you make the most from it.

Kubernetes Training Course

Kubernetes Tips and Tricks You Need to Know

Companies which aim at rolling out large-scale, load-balanced clusters of containers with high availability could get the best from Kubernetes. Kubernetes has found promising application in business as well as enterprise-level deployments. Furthermore, the impact of Kubernetes extends to consumers, client, and staff also. So, let us take a closer look at ways to make the most of Kubernetes.

1. Get the Autocompletion

The first mention in top Kubernetes tips is the use of kubectl commands. You need to bash complete the commands. The process is quite simple and can assure better functionality and flexibility in using Kubernetes. Kubernetes users applying bash could be able to add autocomplete with simple kubectl commands. Users could enter a simple command like this one to achieve autocomplete.

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

You can add autocompletion to the .bashrc by entering this command. So, the next time you open a shell, the autocompletion starts automatically. The autocomplete feature is suitable for long entries in Kubernetes. For example, “-all-namespaces

2. Adding Default Limits and CPU Limits

The next entry among top Kubernetes tips involves the addition of default memory limits and CPU limits to namespaces. Generally, mistakes happen even after being totally careful. For example, an individual can write an application for opening a connection to a database every second. However, the developer could not ensure that the connection to the database closes. So, there is a possibility of memory leak in one of the applications in the cluster. If the application deploys to the cluster without any limit set, then it could crash a node. Therefore, Kubernetes tips suggest allowing default limits to prevent such mishaps.

 The default limits allocation should base on per namespace. Users can achieve default limit allocation with a simple approach. The process is easy and simple like the creation of YAML for limit range and then assignment to the concerned namespace. As one of the best Kubernetes tips, you can create a yaml and then add to the desired namespace. The example for this is “limit-example”. Once this is applied, containers which deploy on the namespace would get a particular limit. Here is an example of a yaml for assigning limit of 512Mi.

apiVersion: v1  
  kind: LimitRange  
   name: mem-limit-range  
   - default:  
       memory: 512Mi  
       memory: 256Mi  
     type: Container

3. Cleaning up Your Docker Images

Kubernetes tips and tricks also show ways of cleaning up docker images. You can find this as a default in kubelet. Upon starting the Kubelet, garbage collection starts immediately when the var, lib or docker achieves 90% capacity. Another fact is that the process of cleaning up starts only when there is no flag set for the kubelet. However, important Kubernetes tips focus on the lack of a default set for an inode threshold. The scenario applies in the case of versions before Kubernetes 1.7. You can find completely used up inodes even with var, docker or lib occupying around 50% of disk space.

As a result, problems arise for workers. Therefore, it is essential to add a flag to the kubelet for users of kubelet versions from 1.4 to 1.6. The following command can help you do so.



The above command shows the defaults that you can find when using Kubernetes 1.7 and the higher versions. In the case of Kubernetes 1.6, there are no defaults for monitoring inode usage. Therefore, the flag helps in solving that problem.

4. Minikube for Local Deployments

Another notable entry in Kubernetes tips relates to Minikube. Minikube is a flexible way of running a Kubernetes cluster locally. Local deployments improve with the application of Minikube. The instructions for using Minikube are simple, and you can download Minikube and install it easily. After completing the installation, a simple command can start the application. The command is “minikube start”. Really, it is so simple! After finishing the command, Kubernetes cluster runs locally.

Minikube is the perfect tool for help in building an application locally and run it locally also. You can find an image built on your system when you do a docker build without running any other commands. A simple command can also help you to use docker build for pushing images to the local Kubernetes cluster. The command is “eval $ (minikube docker-env)”. Enter the command and then you can start building applications on a local Kubernetes cluster.

Kubernetes has become an important part of the container revolution. Want to know more about Kubernetes? Check these interesting Kubernetes facts!

5. Don’t Hand out Generic kubectl Access

Kubernetes tips and tricks also focus on restricting kubectl access. Kubernetes is built for multiple teams deploying to one cluster. However, you should restrict giving out generic kubectl to everyone. The best suggestion, in this case, implies the classification of teams on the basis of a namespace. RBAC policies are the way to go for allowing access only to a particular namespace. The access provided for read, delete, create and out on a pod basis is quite confusing. The process may also take a huge toll on your mind. However, you should prioritize the facility of access to secrets to admins. As a result, you can differentiate between administration privileges for a cluster and deployment privileges.

6. Pod Disruption Budgets

DCA Practice Tests

One of the best Kubernetes tips is the use of pod disruption budgets. Pod disruption budgets are the solution for guaranteeing no downtime for an app on a Kubernetes cluster. Cluster updates will happen with Pod disruption budgets and the nodes will drain out. Therefore, PDBs are mandatory for every deployment that is associated with more than one instance. You can create a PDB by applying a simple yaml to the cluster. Label selectors can help in finding out the specific coverage of each PDB.

You should note that PDB applies in the case of voluntary disruption. So, you cannot expect PDB to kick in when you have a hardware failure. The example of a PDB is as follows –

apiVersion: policy/v1beta1  
  kind: PodDisruptionBudget  
   name: app-a-pdb  
   minAvailable: 2  
         app: app-a

One of the most important Kubernetes tips, PDBs are recommended for better control also. You can find the two most important things in the PDB. They are minAvailable and matchLabels section. The matchLabels helps Kubernetes to see the attachment of a deployment to the PDB. For example, the PDB presented above will apply to deployment with label app: app-a and not for the app: app-b. The minAvailable helps Kubernetes identify a node drain. For example, if app-a is running on Node 1 and Node 1 sees a drain then it will evict app-a only. Why? Because there are two instances currently running. Interestingly, you could be able to control the number of instances that you need to run at a particular time.

Aspiring to become a Kubernetes Certified Administrator? Start your preparation for the Kubernetes Certified Administrator exam.

7. Using Probes Effectively

Another proven mention in Kubernetes tips is checking the health of an app. Kubernetes allows the definition of probes. Kubelet uses the probes for determining the health of the pod and the app. The two types of probes are readiness probes and liveness probes. Readiness probes help in determining the status of a container to receive traffic. Liveness probes help in finding the health of a container or the need for restarting the container. All you have to do is add the configs to the deployment yaml. You can also customize delays, timeouts, and retries.

8. Labels Help a Lot

No list of Kubernetes tips would undermine labels. Labels form a foundation element in Kubernetes. Labels help in loose coupling objects to other objects. In addition, labels help in the query on the basis of labels. The Kubernetes Go client is the ideal choice to watch events based on labels. Labels help in achieving a wide range of functions. The best example for the use of labels is multiple environments in a specific cluster.

For instance, you use the same cluster for qa and dev. So, you could possibly have app-a running on dev and qa at the same time. You may need two service objects for achieving this functionality easily. One service object carries out label select on the app: app-a and environment: dev. The other service object selects on the app: app-a alongside switching dev with qa. So, you have two different endpoints for the same app. As a result, you could also apply to the test at the same time.

Preparing for Kubernetes interview. Prepare with these top Kubernetes interview questions to ace the interview!

9. Go for the GO Client

The Kubernetes Go client gives a lot more than expected. Kubernetes was developed on GO and the add-ons also have their development roots on GO. The Go client has a wide range of interesting things in store for users. Go is ideally suited for tailoring Kubernetes to your preferences. For example, you could try out a deployment engine, a simple clean-up application, or for data collection engine.

10. Keep Cleaning

The final mention in this list of ten Kubernetes tips is cleaning up regularly. Kubernetes is also liable to storage deficit like any other system. The Kubelet performs checks assigned by you alongside performing its own checks. Kubernetes is known for scalability. But if a particular service is scaled up to millions, then the kubelet gets stressed. Therefore, you should try to clean everything when deleting a deployment.

Docker Online Course

Final Words

Finally, the list of top Kubernetes tips and tricks comes to an end. The tips provided in the above discussion aim at improving your Kubernetes usage. On the other hand, you could gain additional insights on using Kubernetes by referring to additional information. For example, “Kubernetes: The Smart Person’s Guide” can work effectively for learning more about the whole Kubernetes landscape. Basics don’t hurt, and you need a lot more of it to make the most of Kubernetes!

You can also take our Kubernets Training Course to advance your Kubernetes skills and knowledge. Not to mention, the Kubernetes community is another good source for updating your knowledge on the container orchestration platform. So, keep reading and searching for more information on Kubernetes!

About Dharmalingam N

Dharmalingam.N holds a master degree in Business Administration and writes on a wide range of topics ranging from technology to business analysis. He has a background in Relationship Management. Some of the topics he has written about and that have been published include; project management, business analysis and customer engagement.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top