Kubernetes

How to avoid Kubernetes mistakes? The quick start-up guide on avoiding them

Learn everything about how to avoid beginner Kubernetes common mistakes. After reading the blog you will know the top 10 Kubernetes common mistakes and how to avoid them when you're starting up.

How to avoid Kubernetes mistakes? The quick start-up guide on avoiding them

What is Kubernetes?

Kubernetes is an open-source platform for container orchestration. It is known as k8s and automates maintaining, scaling, and deploying containerised applications by managing the containers in a cluster using a suite of command-line tools and APIs. 

The Kubernetes architecture comprises a master and several nodes, sometimes known as worker nodes. The nodes' operations and cluster state are under the master's control. Moreover, it controls and schedules containers on nodes and workloads and assigns resources to containers appropriately. Nodes might be physical or virtual machines, but to function with the Kubernetes cluster, they all need access to the kubelet service and the Docker engine. Additionally, to transport data between nodes, a node needs to be connected to other nodes.

Kubernetes utilises a declarative configuration model that makes it simple to create robust systems for both expected and unforeseen changes. By handling the inherent complexity of container and cluster operations through declarative configuration, Kubernetes makes it simple to construct clusters with high availability, scalability, and security.

Despite the many advantages of using Kubernetes, sometimes a complicated deployment might lead to mistakes that might prove harmful in the long run. Let us explore all the Kubernetes common mistakes one by one.

We summarise some common mistakes people make in Kubernetes with methods of avoiding them below.

Kubernetes Common Mistake #1

Using the 'Latest' Tag

Since the version and other descriptions are not sufficiently clear, it would cause chaos to use the most recent tag in production. Furthermore, not knowing what version of the application is in use makes it more difficult to fix problems when they arise. Therefore, it would be ideal to utilise purposeful Docker tags at all times.

Most of us mistakenly believe that the "Latest" tag always refers to an image's most recent push though untrue. Although it has no significance, the "Latest" tag automatically applies to the image.

Kubernetes Common Mistake #2

Not Setting Resource Consumption Limits

To avoid bills and resource utilisation shooting up, we need to take charge and decide which services are necessary and which ones are not. 

One option to take control of resource utilisation is stress testing which keeps the containers’ memory and CPU in check. Kubernetes stores the definitions of limitations and requests in the resource use category. Limits specify the maximum resources, whereas requests describe the minimum resources an application requires to function.

We cannot monitor the application if we do not control the resources. We can set the resource restrictions In the deployment of YAML.

Kubernetes Common Mistake #3

Not Employing Deployment Models

Kubernetes makes it simple with its variety of deployment methods and helps developers solve deploying application problems.

Kubernetes advises utilising the following deployment tactics to maintain your application's availability and ensure that customers are not adversely affected by potential downtimes while installing new software: Rolling, Canary, and Blue-Green.

The Rolling deployment approach is Kubernetes' default method of replacing old pods from an earlier version with new pods over time.

The Canary deployment approach is used for dark and A/B testing launches. This method will witness delayed traffic from version A to version B. It is similar to the Blue-Green approach but gives more control.

In the Blue-green deployment approach, one version will always be active and live, while both blue and green versions are released simultaneously. Consider the colours green and blue as the new and old versions, respectively. As a result, all traffic is first routed by default to version blue. However, if version green passes all the conditions, traffic from version blue is switched to version green.

Kubernetes Common Mistake #4

Ignoring Health Checks

When deploying services to Kubernetes, health checks are crucial to ensure they continue functioning as planned.

The health of the pods and the entire Kubernetes cluster must be known to verify that everything is operating as intended. There are readiness, liveness, and startup probes that can help us with this by letting us understand how our app and its services are doing. The startup probe guarantees that the pod is successfully launched and constructed.

The liveness probe allows us to check if the application is alive using the liveness probe. The readiness probe is used to ascertain whether the application is prepared to receive traffic.

Kubernetes Common Mistake #5

Using Only One Kind of Container
(i.e., Stateless) in Production Environments

Although containerisation and containers were initially intended for stateless applications, stateful applications are now supported to a great extent.

Employing stateful apps has become essential since Kubernetes supports modern data-driven applications and enables containerisation.

Another Kubernetes common mistake that developers make is using stateless containers exclusively in production environments when they ought to be employing both stateless and stateful containers. Contrary to popular misconceptions, containers differ significantly from one another. To avoid losing data, it can be stored in stateful containers on discs or other persistent storage. Contrarily, stateless containers only retain data while active, after which it is permanently lost (unless it is backed up beforehand). So, it is a great practice to use both stateful and stateless containers.

Kubernetes Common Mistake #6

Duplicated Deployments

Another frequent mistake that developers perform is duplicating a deployment plan. This usually occurs whenever we create many replicas of the same state and deploy them concurrently to other clusters. 

This means that the deployment will continue to process requests even if one cluster is down. When we put the clusters back up, or they come back up, both replicas will be processing requests and tripling your requests because there are two sets of replicas operating. This might cause the RAM and CPU to oversubscribe on the underlying hosts. One way to fix this is to adopt a service type like Daemon Set or Headless Service by ensuring that only one deployment version is active at any given moment.

Kubernetes Common Mistake #7

Deploying the Application Without Considering
Monitoring and Logging Requirements

Ignoring the necessity for monitoring and logging can prove to be devastating. This omission leads to developers being unable to understand how their application or code is functioning in a real-world setting.

To avoid this error, developers should set up a monitoring system and a log aggregation server before deploying their application on Kubernetes. We may measure the performance of our application and determine what modifications are necessary to improve its performance after these technologies are in place.

Vendor lock-in occurs when we just use the tools and services offered by Kubernetes itself rather than employing third-party solutions. For instance, we may deploy our container using a CRI container runtime interface instead of using rkt containers or Docker. Additionally, many developers experience pandemonium either because their clusters do not have adequate capacity or because their applications are deployed at the wrong time of the day.

Kubernetes Common Mistake #8

Mounting Host File Systems in Containers

An anti-pattern that frequently fails is mounting host file systems in containers. To tackle this, we must understand that no files produced or updated inside the container are accessible from the outside world.

Data persistence is one of the use cases of mounting host file systems in containers. Mounting the host's local directory as one of the directories in the container's file system is the simplest way to accomplish this. This will ensure that anything added to that directory is retained on the host computer.

But there are drawbacks to mounting our host file system:

  • Multiple containers cannot share state, which means that we cannot mount two different folders on two separate hosts.
  • Other containers won't be able to see any modifications made to the file system on our host.
  • Any mounted folders cannot have their files managed without first modifying their ownership and permissions.

To avoid these repercussions, don't mount any file systems from your host inside a container unless you require them for data persistence.

Kubernetes Common Mistake #9

Deploying a Service to the Wrong Kubernetes Node

Another Kubernetes common mistake developers make is deploying a service to the incorrect node. Nodes in Kubernetes can either be worker nodes or master nodes. In Kubernetes, each job has a scheduler or a controller. While the scheduler runs on a worker node, the controller runs on a master node. 

Worker nodes only carry out the tasks that their masters give them. This implies that our service may not operate correctly or at all if it is deployed to the incorrect node. Additionally, it will take longer than intended for our new containers to start up since they must wait for a scheduler to become available so that tasks can be assigned before proceeding.

The primary responsibilities of the master node include synchronising with matching workers and overseeing cluster-level resources, including permanent data storage, network, and volumes.

To prevent this, we need to know the sort of node they are executing on, master, or worker, before deploying our services. Additionally, before launching any containers, we should ensure that the pod has access to the other pods in the cluster with which it needs to communicate.

Kubernetes Common Mistake #10

Deploying the Application Without Any Security Configurations in Place

Security is something we should constantly consider while launching our application. Some of the examples include - using an endpoint that is accessible from outside our cluster, not protecting our secrets, running privileged containers properly, etc. are a few examples.

For any Kubernetes implementation, security is a core component. Some of the security obstacles are:

  • Storage - Securing storage in a cluster ensures that data is protected so that only authorised users and processes can access it.
  • Networking - To ensure that communication between containers is routed safely within the cluster, Kubernetes networking entails maintaining service and overlay networks.
  • Authorisation - Controlling access to resources in a Kubernetes cluster requires authorisation and authentication.

The stored data is accessible through the REST interface on the Kubernetes API server. This implies that consumers can access any data stored in the API by making straightforward HTTP queries. We must set up authentication for the API server using techniques like username/password or token-based authentication to keep this data safe from unauthorised users.

In addition to the cluster, its configurations and secrets also need to be secured. We must set up several security rules on the cluster to protect it from flaws. One such measure would be to use RBAC to secure a Kubernetes cluster. By restricting access to resources based on the responsibilities that users have been given, role-based access control can be used to secure Kubernetes clusters. These roles have the options of ‘operator” or "admin" configuration. The operator role has restricted access permissions to cluster resources compared to the admin role's complete access. By doing this, we can manage and regulate who has access to the cluster.

In this article, we explored 10 Kubernetes common mistakes developers make while using Kubernetes and how to avoid them. 

The kubernetes common mistakes are summarised below

  • Using the ‘Latest’ Tag
  • Not Setting Resource Consumption Limits
  • Not Employing Deployment Models
  • Ignoring Health Checks
  • Using Only One Kind of Container (i.e., Stateless) in Production Environments
  • Duplicated Deployments
  • Deploying the Application Without Considering Monitoring and Logging Requirements
  • Mounting Host File Systems in Containers
  • Deploying a Service to the Wrong Kubernetes Node
  • Deploying the Application Without Any Security Configurations in Place

Avoiding these Kubernetes common mistakes not only help prevent chaos in the long-run but also help a lot of time, resource and money.

Diksha B Patro
/
September 12, 2022