Managing Resources in Kubernetes: 7 Things to Know
Harshit Mehndiratta
Harshit Mehndiratta
May 25, 2020
/
5 minutes read

Managing Resources in Kubernetes: 7 Things to Know

Kubernetes is an effective container management tool that automates container deployment, scaling, and load balancing. It manages containers or pods in a manner that promotes resource-saving and productivity. Kubernetes provides plenty of customizations to end-users when it comes to optimizing the deployment of pods. Here is a list of seven for squeezing the most performance and efficiency from your Kubernetes distribution.

1. Defining Resource requests and limits

By default, in Kubernetes, containers are deployed without any limits on the amount of resources they can consume. One handy way of managing these resources is by using request and limit features of Kubernetes. Request and Limit specifier can change and specify the amount of resources used by each container by limiting the use of CPU, memory, and storage space. For example, you have an e-commerce website with a microservice that handles email service for customers, so the primary use of microservice is to handle network requests that are not memory intensive. Thus, a container with less memory will save precious dollars and decrease the cluster’s overall load.

Configuring resources of a container using request and limit Here is a resource profile of a container in Kubernetes with default memory and CPU size, which can be edited for less memory by changing request and limit specifier.

resources: requests: memory: 2.0Gi cpu: 200m limits: memory: 4.0Gi cpu: 900m

Resource profile of a container with (less memory):

resources: requests: memory: 512Mi cpu: 200m limits: memory: 1Gi cpu: 900m

2. Configuring Node Affinities

Not every container or pod in a cluster have the same purpose. Some pods might have to run CPU intensive applications while other pods have to handle memory-intensive tasks. So how can we prioritize containers for high memory usage or vice versa? Prioritization for pods is available in Kubernetes via the Node Affinity feature using node selector. The node selector tool provides labels for CPU or memory prioritization, which should be specified according to the tasks that nodes have to handle. For example, let’s say that you have two nodes: one that offers high CPU core count, which is beneficial for CPU intensive tasks, and a fast memory node that offers faster access to data, and you want a node with fast memory. The best way to do it by adding a selector in the spec section and specifying MemoryType:HIGHMEMORY. For a node with higher CPU Count you should specify the CPUType:HIGHCORE to get better CPU performance see the below syntax.

nodeSelector: CPUType: HIGHCORE

Kubernetes also offers other features such as core prioritization and GPU support, which further increase a node’s performance. CPUManager:, which is a built-in feature in the Kubernetes environment, offers core affinity, which can prioritize high-performance cores for heavy workloads. Accelerator: provides graphic processing support to CPU under heavy graphics workloads.

3. Building Container Images from scratch

Optimizing a container image plays a crucial role in increasing the efficiency of containers or pods in Kubernetes. Optimized container images promote faster boot times and diagnosis, leading to better management of pods using Kubernetes. There are various ways by which the container image can become optimized.

  • Creating different container images for different microservices.
  • Download the base image of distribution, and only install necessary applications and libraries since big images take more time to pull over from the hub.
  • Container image should contain health check libraries so Kubernetes can manage them in case of failure or downtimes.
  • Using a resource-friendly Linux distribution (like Alpine or CoreOS) as they hog fewer resources.

4. Using Namespaces to specify resources on a cluster level

Specifying resources on a container level is a great way to increasing efficiency and productivity, but what to do when we have thousands of containers or a cluster to specify. Here is where Namespaces comes into play. Namespaces are logical partitions of Kubernetes clusters that made for logical isolation of teams in the organization. You can easily set requests and limits for resources as a whole for all the containers inside a cluster by creating namespaces. You can also set the number of resources which can be distributed to individual containers inside a namespace, by setting a Limit range.

5. Using Autoscaler to scale clusters and containers

Autoscaler is a tool in Kubernetes which can be used to resize clusters and containers, based on resources needed to use. Autoscaler automatically adds a new node to a cluster whenever a container does not respond due to requests overload. It also removes nodes automatically whenever nodes are not in use.

6. Deploying Kubernetes clusters in the right location

The nodes’ geographic location plays a major role in providing a smooth and low latency experience to the customers. For example, node clusters located in the United States will have faster response times for local customers than in Europe. So, before deploying Kubernetes clusters at any location, one should carefully plan and find zones where clusters will work efficiently for their target customers. Note that every zone will have a cloud service provider that will have certain restrictions. It is necessary to study the demographic and then deploy and expand clusters.

7. Choosing high-quality hardware for Node Clusters

Not all CPUs, memory chips, and storage hardware are created equal. For example, solid-state storage drives offer better read/write performance than HDDs, and NVMe SSDs are even faster than traditional SSD’s. DDR4 memory will retrieve data faster as compared to DDR3 memory. A CPU with more cores will be more beneficial for Node, which handles data rendering requests. So, better and long-lasting hardware will not only offer better performance for the node clusters but will also provide better management of node clusters using Kubernetes.

Conclusion

Overall, Kubernetes is a very efficient container management environment that offers a wide variety of features. The more time you spend exploring and adequately configuring your workloads using Kubernetes, the more resource-effective your organization becomes. Also, Kubernetes built-in features and open source tools are best to get started on container orchestration as they are easy to use and has a human-readable syntax.

message