Essential Tips and Tricks for Kubernetes

Level Up AWS Automation Post
5 Ways to Improve Cloud Automation Using AWS Snapshots, CloudWatch and More
August 20, 2019
OpenShift Kubernetes
The 5 Most Important Differences Between OpenShift and Kubernetes
November 4, 2019
Show all

Essential Tips and Tricks for Kubernetes

Containerized environments have gained considerable popularity among developers, as they enable standardized, portable and secure workloads. To help manage containers, organizations typically use a container orchestration system like Kubernetes, which enables the deployment of containerized applications on a large scale.

Read on to learn how you can take advantage of Kubernetes for a more productive and efficient work environment.

#1. Keep Your Containers in Order

When you delete a deployment, it is important to clean up Docker images to keep the Kubelet from getting stressed. The Kubelet does this by default, though you can add your own checks. Make sure you keep updating your checks and cleaning your containers regularly.

#2. Control Access to Kubectl

Don’t provide the same access to everyone. You can use Role-Based Access Control (RBAC) to grant differentiated access to each team deploying to the same cluster. This will mean that the combination of read, create and delete access will be granted only to a specific namespace. For example, access to secrets should be restricted to admins, even if someone else will be deploying the cluster.

#3. Take Advantage of Autocompletion

You can use the autocomplete feature to automatically fill in long entries in Kubernetes. The autocompletion is executed by Bash and can complete kubectl commands. To add autocompletion to the .bashrc, enter this command:

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

#4. Add Memory Limits to Namespaces

You can use default memory limits or CPU limits to prevent a crash in the event of a memory leak. Setting a limit ensures that connections to databases will close at the specified point, rather than allowing memory leaks to continue indefinitely. Limits should be allocated according to namespaces. You can create a YAML and add it to the chosen namespace, which will apply the limit to all containers deployed on the namespace.

It is important to apply these limits as you cannot rely on all developers to remember to close every connection they open when writing an application. You should always plan with the assumption that mistakes happen, and when they do, the limits you’ve set will kick in and prevent a crash.

#5. Use Labels

Labels are an essential element in Kubernetes and should be leveraged to loose-couple objects to each other. Labels also make it easier to run queries and enable the use of multiple environments in a single cluster. For example, you could have app-a running on qa and dev simultaneously, although they share the same cluster. This is made possible by using two service objects, providing two separate endpoints for the application.

#6. Leverage Third-Party Tools

One of the advantages of Kubernetes is that it integrates with a large number of tools and services from different vendors. You can use a managed Kubernetes service to help you make the most of Kubernetes’ features such as databases and prebuilt applications. This will also alert you to any updates so you know you always have the latest version.

#7. Use Plugins

You can install kubectl plugins to extend your kubectl with custom commands. Each plugin will have a name such as kubectl-example and must be copied to a directory in your path. You can create your own plugins using any executable script (Bash, Python, etc). However, you should make sure that you don’t create any duplicates.

To see a list of all your plugins, use this command: 

$ kubectl plugin list_

#8. Use Auto-Generated Aliases

You can save typing with shell aliases for common kubectl commands. There are approximately 800 aliases in the kubectl-aliases project, which are auto-generated according to a simple scheme, so you don’t have to remember them all. 

An alias typically contains several components, including resource, operation, base command and multiple options. This is in turn simplified. For example, the command kubectl get pods -o yaml –all-namespaces becomes thee alias kgpooyamlall, according to the scheme below:
Kubectl Alias Scheme

Kubernetes Post Image

Conclusion

Kubernetes has become a ubiquitous platform for developing applications, and its popularity is a major advantage over other container orchestration systems. The large community and growing selection of related tools and services mean you can use Kubernetes to develop an ever-increasing range of applications, in a secure and adaptable environment. The tips and tricks mentioned above should provide you with a starting point when planning your Kubernetes deployments for an enterprise scale.

James Lee
James Lee
James Lee is a passionate software wizard working at one of the top Silicon Valley-based startups specializing in big data analysis. In the past, he has worked on big companies such as Google and Amazon In his day job, he works with big data technologies such as Cassandra and ElasticSearch, and he is an absolute Docker technology geek and IntelliJ IDEA lover with strong focus on efficiency and simplicity.

Leave a Reply

Your email address will not be published.

LEARN HOW TO GET STARTED WITH DEVOPS

get free access to this free guide, downloaded over 200,00 times !

You have Successfully Subscribed!

Level Up Big Data Pdf Book

LEARN HOW TO GET STARTED WITH BIG DATA

get free access to this free guide, downloaded over 200,00 times !

You have Successfully Subscribed!

Jenkins Level Up

Get started with Jenkins!!!

get free access to this free guide, downloaded over 200,00 times !

You have Successfully Subscribed!