Kubernetes for beginners

Photo by Clark Tibbs on Unsplash

Kubernetes for beginners

What is Kubernetes?

Definition: Open source container orchestration tool, Developed by Google,It helps you manage containerized applications in different deployment environments.

What problems does it solve?

The rise of microservices has led to an increase in the use of containers. This, in turn, has resulted in the development of large applications based on microservices. Managing these many containers across multiple environments using scripts or custom tools can be very complicated. So, orchestration tools like Kubernetes will manage it for you.

The features that it offers are

  • High Availability or no downtime
    High availability in Kubernetes refers to the ability of applications and services to remain operational and accessible even in the event of failures or disruptions. It involves replicating pods, distributing them across nodes, utilizing load balancing, and implementing fault tolerance mechanisms to ensure uninterrupted service.

  • Scalability or high-performance
    Scale your application up and down with a simple command, with a UI, or automatically based on CPU usage.

  • Disaster Recovery, backup and restore
    Kubernetes restarts containers that fail, replaces containers, kills containers that don't respond to your user-defined health check, and doesn't advertise them to clients until they are ready to serve.

Components of Kubernetes

There are lots of components of Kubernetes, here I have explained the most used components which are sufficient based on the scope of this article

Node

the node is the smallest unit of computing hardware in a Kubernetes cluster. Nodes can be physical on-premises servers, or VMs that reside either on-premises or at a cloud provider.

Pod

The smallest unit of abstraction over a Docker container, creates a running environment. You only interact with the Kubernetes layer, usually meant to run one application.

Services

Each pod gets its own internal IP address. However, pods can die very easily, and when they are recreated, they are assigned new IP addresses. Continuously updating these IP addresses is not feasible.

A service provides a static IP address that can be attached to each pod.

The lifecycle of services and pods are not connected.

Ingress

Helps you access your application through the browser
Instead of going directly to the service, the request first goes to the ingress, which then forwards it to the service. The ingress is essentially the domain name of your application, allowing you to access the application through the browser.

Config Map and Secrets

where we define the configurations of our cluster,
for example, how the pods will communicate with each other, what is the replication strategy, list of whitelisted IP addresses, etc

Example of a config map

apiVersion: v1
kind: Pod
metadata:
  name: configmap-pod
spec:
  containers:
    - name: test
      image: busybox:1.28
      command: ['sh', '-c', 'echo "The app is running!" && tail -f /dev/null']
      volumeMounts:
        - name: config-vol
          mountPath: /etc/config
  volumes:
    - name: config-vol
      configMap:
        name: log-config
        items:
          - key: log_level
            path: log_level

Volumes

On-disk files in a container are ephemeral, which presents some problems for non-trivial applications when running in containers. One problem occurs when a container crashes or is stopped. Container state is not saved so all of the files that were created or modified during the lifetime of the container are lost. During a crash, kubelet restarts the container with a clean state. Another problem occurs when multiple containers are running in a Pod and need to share files. It can be challenging to setup and access a shared filesystem across all of the containers. The Kubernetes volume abstraction solves both of these problems.

At its core, a volume is a directory, possibly with some data in it, which is accessible to the containers in a pod

Bibliography