DevOps: Tools. Kubernetes

Based on the article

Kubernetes is a sophisticated mechanism designed to make systems scalable, resilient, and easy to deploy. It allows us to automate container orchestration

Main benefits:

  • Automate the start and rollback of deployments

  • Manages the resources and can scale the required resources for the applications

  • Applications in Kubernetes are rolled out and tested without administrators

  • Standardize the work with Cloud Service Provider

Basic components

Pod

The smallest unit that can be launched on a cluster node.

Pod contains containers

The containers in the pod share:

  • port numbers

  • Linux kernel namespaces

  • network stack settings

So when you scale your application within k8s, you should increase the number of pods rather than the number of containers in one particular pod.

By default containers inside pods are restarted automatically fixing intermittent problems for you.

Pods do not require the use of Docker containers. If necessary, you can also use other application containerization technologies, such as rkt.

Desired state

You can specify the required state of running pods instead of writing how to achieve that state. For example, if a pod stops working for some reason, k8s will recreate the pod based on the specified desired state.

Object

An object in k8s is a record of intent — the desired cluster state.

Pod is an Object

Every k8s object includes two nested object fields that govern the object's configuration:

  • the object spec

  • the object status

Objects also serve as an additional abstraction layer above the container interface. You can interact with the objects' entities instead of interacting directly with containers.

Service

Service plays the role of an access point to sets of pods that provide the same functionality as the underlying pods. There are different types of services:

  • ClusterIP

  • NodePort

  • LoadBalancer

  • ExternalName

ClusterIP — it exposes the Service on a cluster-internal IP, so you can only access it using the Kubernetes proxy.

Controllers

  • ReplicaSet - checks that a certain number of copies of pods are running,

  • StatefulSet - is used with stateful applications and distributed systems

  • DemonSet - is used to copy pods to all nodes in the cluster or only to specified nodes

Controllers implement a control loop — a non-terminating loop that monitors the state of its subsystems, then makes or requests changes where necessary. Each controller tries to move the current state of the cluster closer to the desired state.

Deployment

The Deployment object is an example of how k8s turns the tedious process of manually updating applications into a declarative activity that can be repeated and automated.

The Deployment object allows us to automate the transition from one version of an application to another and represents a layer above the replica sets and actually manages the replica sets and pod objects. This is done without interrupting system operation. In case of an error during that process, it will be able to quickly return to the previous, working version of the application. Also, using Deployment we can scale the applications very easily.

Architecture

Master Node

Kubernetes Control Plane is a group of processes controlling the state of the cluster. Typically, all these processes are run by a single node in the cluster and this node is also called a Master node.

The Master node can also be replicated for redundancy and fault tolerance.

The kubectl command-line tool is an interface to communicate with the master in the cluster through the API.

On each Master Node there are the following basic components that ensure the operation of all system components:

  • etcd - strongly consistent, distributed key-value store used by k8s for configuration management and service discovery.

  • kube-apiserver - the main control endpoint for the cluster. Any commands from kubectl are sent as API requests to it on Master Node.

  • kube-controller-manager - a daemon that embeds the basic control loops shipped with k8s.

  • kube-scheduler - schedules tasks on all available nodes in the cluster

    determines on which Worker Node to create a new pod, depending on the required resources and node workload.

Worker Node

Worker Node is a virtual or physical machine that has Kubernetes components to launch pods. There are two components running on Worker Nodes:

  • kubelet - checks the kube-apiserver for a description of new pods to be deployed on the given node and handles the Docker (or another containerization system) through its container management API.

  • kube-proxy - s the equivalent of a reverse proxy server, responsible for forwarding and proxying requests to the corresponding services or applications in the private network of the k8s cluster.

Of course, this is far from all the k8s entities and by no means all details. There are much, much more.

Last updated