Kubernetes

Similar to Docker Swarm is Kubernetes (often abbreviated as k8s), an open-source Google project for managing containers in a cluster.

Kubernetes acts as a framework for deploying, scheduling, maintaining, updating, and scaling microservices. In essence, it abstracts the process of deploying the service from the user and actively monitors the state of the application infrastructure to ensure integrity. If a problem occurs, Kubernetes can automatically rebuild and redeploy a failed container.

A key difference between Kubernetes and Docker Swarm is how they treat clusters of containers. With Docker Swarm, individual containers are unified under a single API. With Kubernetes, containers are grouped into logical units which are then managed, monitored, and assigned resources by the cluster master. One of the key features of Kubernetes is that it enables users to define the ultimate state of the cluster, while managing the cluster’s various components to match that state.

In addition to the Scheduler, the Kubernetes master includes an API Server and a Controller Manager as we see in Figure 5.3. The kubectl client talks to the API Server on the master node and sends a configuration for a replication controller, with a pod template and desired replicas. Kubernetes uses this information to create a number of pods. The scheduler then looks at the cluster state and schedules work on the nodes. The kubelet, an agent running on each node, monitors changes in the set of pods assigned to it and then starts or kills pods as needed.

Image

FIGURE 5.3: Kubernetes cluster overview

Components

A basic Kubernetes cluster consists of node agents (known as kubelets) managed by a Kubernetes Control Plane running on a master node.

Pods

Kubernetes groups related containers into logical units called pods. Pods are the smallest components that can be created, deployed, or managed by Kubernetes. However, they generally consist of containers that perform complementary services. For example, a pod that provides a website could consist of a web server container and data storage container. Containers within a pod can view other containers’ processes, access shared volumes, and communicate via message queues.

Replication Controllers

When running multiple instances of a pod, Kubernetes controls the number of instances by using a replication controller. A replication controller ensures that a specified number of pods are available at any given time. For instance, if you have two instances of a pod running for load balancing purposes and an instance fails, a replication controller will automatically start a new instance.

Labels and Selectors

A label is metadata attached to Kubernetes objects such as pods. A label consists of a key/value pair that can be attached, modified, and removed at any point during the lifetime of the object. Labels are generally used to organize and group various objects. A label selector enables us to group sets of objects based on the value of a label.

Services

Similar to how pods define a set of related containers, services define a set of related pods. Services are a stable abstraction in the cluster that provide routing, service discovery, load balancing, and zero downtime deployments. Applications consuming the service can use either the host name or IP address of the service and the requests will be routed and load-balanced across the correct pods.

When a service is created, Kubernetes assigns it a unique IP address, and although pods will come and go, services are more static.

Volumes

Containers are stateless by design. When a container is deleted, crashes, or refreshed, any changes made to it are lost. With volumes, containers can preserve data in a directory that exists outside of the container. Volumes also enable containers to share data with other containers in the same pod. Kubernetes supports several types of volumes, including local folders, network-attached folders, cloud storage volumes, and even Git repositories.

Names and Namespaces

Each object in Kubernetes is identified by an identifier and a name. Unlike labels, names and IDs are unique for each object. Names can be provided, but an ID is generated by Kubernetes.

Namespaces enable you to create multiple virtual clusters on the same physical cluster. Objects that exist in the same namespace are restricted to that namespace; they can communicate with each other, but not with objects in other namespaces. There are some exceptions, such as nodes, persistent volumes, and namespace objects themselves.

Other Components

Kubernetes supports other features such as annotations for attaching non-identifying metadata to objects, secrets for storing sensitive data, and more. For additional information, see the Kubernetes User’s Guide at http://kubernetes.io/v1.1/docs/user-guide/README.html.

Kubernetes on Azure

Kubernetes can be deployed on Microsoft Azure, and a set of scripts for easily deploying to Azure are maintained in the Kubernetes project. These scripts can be found on the Kubernetes site (https://kubernetes.io) in the Getting Started section of the documentation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.64.172