Skip to main content

Command Palette

Search for a command to run...

What is Kubernetes?

Published
6 min read
What is Kubernetes?

Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of containerized applications.

The modern software development world is in the era of containers.

With the adoption of microservices architecture and containerized applications, organizations might have a hundred or thousands of containers running to support their workloads.

Kubernetes is now a standard for managing and scaling complex software environments and I will highlight in this article why I think it has gained such popularity.

Why Kubernetes?

Kubernetes helps organizations and their teams manage container-related tasks making it easier to deal with the application lifecycle.

What does Kubernetes do?

Deployment: execute container deployments with a simple configuration file using built-in deployment strategies out of the box.

Service Discovery: Kubernetes has the ability to expose a container to the internet or to other containers using DNS or IP addresses.

Storage: mount volumes for containers using local file storage or cloud storage.

Load-Balancing: load distribution across the network based on built-in metrics such as CPU utilization or number of requests per target.

Autoscaling: Kubernetes can spin up more containers to meet the demand when traffic spikes, as well as remove the same containers when the high demand is gone.

Kubernetes has a lot of other features to help the application’s lifecycle management be easier, and it gives you all this stuff out of the box to help organizations orchestrate all of their workloads running in containers.

Cloud Providers

Kubernetes is supported by major cloud providers such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud.

Each of them offers a managed solution for Kubernetes, helping organizations to get a Kubernetes environment integrated with many other services within the cloud.

Community

This is one of the strongest points of Kubernetes, as it has a vast open-source ecosystem constantly growing, with a lot of tools and knowledge sharing to support the Kubernetes adopters.

Kubernetes Architecture

A Kubernetes cluster consists of two main building blocks:

  • Control Plane: also known as master node

  • Nodes: consisting of a set of worker machines to run the workloads

A Kubernetes cluster is composed of several components, each one responsible for a specific function. These components working together execute the orchestration of all the containers running the workloads.

Control Plane Components

The control plane components are responsible to make global decisions about the cluster, such as scheduling a new Pod when the desired state of deployment is unsatisfied, for example.

kube-apiserver: exposes the Kubernetes API, which plays a front-end role in allowing communication with the control plane.

etcd: a highly-available key value store used as Kubernetes backing store for all cluster data.

kube-scheduler: it watches the newly created Pods **with no assigned node and assigns these Pods to a node with the capacity to accept new Pods.

kube-controller-manager: it runs controller processes, as logically each controller is a separate process they are all compiled into a single binary and run in a single process.

cloud-controller-manager: it embeds cloud-specific logic and links the Kubernetes cluster to the cloud provider’s API, and separates the components that interact with the cloud provider from the ones that only interact with the cluster.

Node Components

kubelet - it's an agent running on each node and it makes sure the containers are running in the Pods. The Kubelet is responsible to take the Pod specs declared as the desired state and ensuring that described pods are running and healthy.

kube-proxy - it's a network proxy that runs on each node maintaining the network rules and allowing communications to the Pods from network sessions inside or outside the cluster.

Container Runtime - it's the software responsible for running containers. Usually, the most common one is Docker, but Kubernetes supports any other implementation of the Kubernetes CRI (Container Runtime Interface).

What is desired state?

Kubernetes works with a declarative approach, which means you can describe the state you desire for your application to be running.

You can specify the parameters of your workloads, such as the container image, the number of replicas, and the resources needed to run the workload such as CPU and memory for example.

This state description is called a manifest, and it's implemented using the YAML language.

You can see below a simple example of a Kubernetes deployment definition.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

The manifests can be stored in a Git repository, to keep the history and generate self-documented deployments. As part of the CD (Continuous Delivery) process, the manifests should be applied to the Kubernetes cluster to deploy the workloads based on the specifications they should be running.

Autoscaling

Autoscaling refers to the ability to resize the cluster in order to support any increase in load as well as any decrease.

When the demand gets high for some workloads it’s needed to scale out the number of Pods and the number of nodes to react quickly and avoid any disruption. The cluster should be able also to scale down the resources to avoid any waste of resources and money when the load decreases.

The Metrics Server is responsible for collecting resource metrics from Kubelets and exposing them in Kubernetes API through Metrics API for use by Horizontal Pod Autoscaler.

The Horizontal Pod Autoscaler gets the metrics provided by the Metrics API in order to react to the high demand of certain workloads to deploy more Pods. Kubernetes has the ability to either increase or decrease the number of replicas for a Deployment or Statefulset to match the demand.

The desired number of replicas of a Deployment is tweaked to match observed metrics like average CPU utilization, average memory utilization, and also custom metrics that can be specified.

The Cluster Autoscaler is a tool to resize the cluster in a number of nodes to match the number of Pods according to horizontal autoscaling. In case of Pods fail to run due to insufficient resources, the Cluster Autoscaler is responsible to add more nodes to the cluster to accommodate the new Pods. Also, in the case of nodes being underutilized for a certain period of time, the Cluster Autoscaler will shut down those resources in order to avoid waste of time and money.

Health Checks (Probes)

Another important feature of Kubernetes is the ability to monitor and react to the state of Pods

to make sure they are healthy. The Probes (health checks) help to monitor when a Pod is started, is ready to receive traffic, and is still alive and working properly.

It’s possible to configure the probes using HTTP endpoints or even custom scripts such as Bash for example.

Startup Probe: used to know when a container application has started. When this probe is configured it disables the readiness and liveness probes until it succeeds.

Readiness Probe: used to know when a container is ready to start accepting traffic. The Pod is only considered ready when all o its containers are ready. When the Pod is not ready it is removed from the load balancing and not used to support workloads.

Liveness Probe: used to know when to restart a container. This probe can be considered as a heartbeat for containers to make sure the applications are up and running.

Conclusion

Kubernetes is one of the most powerful tools in the modern software world.

It provides the ability to grow and scale applications easily and it’s already a market standard for containerized applications. As a cloud-agnostic technology, it makes it possible to keep your workloads decoupled from vendor locking and also enables the multi-cloud approach seamless.

The Kubernetes environment will constantly grow and more and more tools will be available to help companies modernize their infrastructure for containers.

I’m excited about the Kubernetes future and looking forward to keeping learning and sharing knowledge with this amazing community!