What is Kubernetes

Kubernetes is today’s most popular open source container management platform, which is the open source version of the well-known Google Borg. Google launched Kubernetes in 2014, with version 1.11 as of this publication. Kubernetes comes from the Greek word meaning helmsman, and K8S is an abbreviation because there are exactly eight letters between the beginning and the end. Based on container technology, Kubernetes can facilitate cluster application deployment, capacity expansion, capacity reduction, self-healing mechanism, service discovery, load balancing, logging, monitoring and other functions, greatly reducing the workload of daily operation and maintenance.

Kubernetes is primarily targeted at applications composed of multiple containers. It therefore groups containers using pods and labels into tightly coupled and loosely coupled formations for easy management and discovery.

All operations in Kubernets can be done through the Kubernetes API, through the API to manipulate objects in Kubernetes, including Pod, Service, Volume, Namespace, etc. The overall structure of Kubernetes is shown below:

Master

Also called a Cluster Control Plane.

Node

A Node can be a physical machine or virtual machine, and each Node has a service that can run Pods. It is managed through the Master node. Nodes are actually provided by cloud providers, and creating a node in Kubernetes management is really just creating an object in Kubernetes that represents the node.

Node contains the following information:

  • Addresses: includes host names, internal IP Addresses, and external IP Addresses.
  • Condition: describes the running status, including OutOfDisk, Ready, MemoryPressure, PIDPressure, DiskPressure, NetworkUnavailable, and ConfigOK.
  • Capacity: Describes node resources, including CPU, memory, and the maximum number of Pods that can be scheduled onto the node.
  • Info: contains basic information such as kernel version, Kubernetes version, Docker version, and OS.

Kubernetes object Objectes

Objects are persistent Objects in the Kubernetes ecosystem that reflect the running state of the cluster. These states include what applications (containerized) are running on the node, the resources available to the application, and the management policies of the application. Kubernetes Object is a record of the intent. Once Objects are created, you tell the K8S system to keep the Objects in their desired state at all times. Object contains two properties: Spec and Status. Spec contains some properties of the Object. Status is the actual Status of the Object.

For example, Deployment is the Object that represents the health of the application in the cluster. To create a Deployment, we specify a Spec to run three instances simultaneously. K8S reads the Spec and then runs three instances. If there is a problem with one of the instances during the run, K8S will rerun an instance.

As mentioned, Kubernetes manipulates objects through apis that accept jSON-formatted parameters, but the CONCatenation of urls is very unintuitive, so we can write the parameters in a YAML file. When using apis to manipulate objects, objects need to be uniquely identified by Names or UUIds, such as/API /v1/ Pods /some-name requesting a POD object with name. Kubernetes Names must contain less than 253 characters and only lowercase letters, hyphens (-), and underscores (_). UID is the unique identifier Kubernetes generates for an object.

1. Pod

a single instance of an application in Kubernetes

A Pod is the smallest unit that can be created and deployed in Kubernetes. The Pod contains the application container, storage resources, unique network IP address, and parameters for the container to run. Pod internal containers share network and storage resources. Docker is the most common container running environment in Pod, but it still allows users to use other container environments.

There are two ways to use pods: one Pod per container, and multiple containers running in a Pod. Pods is designed to allow multiple container processes to be combined into a single service, and this usage is a relatively advanced feature that is only used when there is tight coupling between programs.

Restarting a container in a Pod should not be confused with restarting the Pod. The Pod itself does not run, but is an environment the containers run in and persists until it is deleted.

The Pod life cycle has several states

2. Pods and Controller

Controller Provides Pod creation, management, capacity expansion, replication, and self-healing functions within a cluster.

2.1 Deployments

Deployment is a new generation of objects for Pod management that offers more functionality and is easier to use than Replication Controller.

2.2 StatefulSets

In Kubernetes, both Deployment and ReplicaSets are effective means of running stateless applications. But these two approaches are not appropriate for stateful applications. The purpose of StatefulSet is to provide the right controller support for a large number of stateful loads.

2.3 DaemonSet

DaemonSet enables all (or certain) Nodes to run the same POD. When the node is added to kubernetes cluster, the POD will be scheduled to run on this node by DaemonSet. When the node is removed from Kubernetes cluster, the pod scheduled by DaemonSet will be removed. If DaemonSet is deleted, All pods related to this DaemonSet will be deleted.

2.4 ReplicationController

A Replication Controller is called a replica Controller. The replica controller ensures that the default number of Pod copies associated with an RC in the cluster is always maintained.

2.5 ReplicaSet

ReplicaSet is not fundamentally different from ReplicationController except by name, and it supports integrated selectors (ReplicationController only supports equations).

2.6 the Job

In some cases, you want to run containers to perform a specific task, and once the task is completed, there is no need for the container to exist. In this scenario, creating a POD is not appropriate. So that’s Job, Job is a one-off task. Running a container through a Job automatically exits when its tasks are finished and the cluster does not wake it up again.

2.7 Garbage Collection

Kubernetes recycling management controller, Kubernetes garbage collection by kubelet management, query clearing a container per minute, once every five minutes query clear image. The first container collection is one minute after Kubelet starts and the first image collection is five minutes after Kubelet starts.

2.8 a CronJob

This is a controller that performs a scheduled task.

3. Service

Kubernetes’ Service is a logical abstraction of a set of Pods defined by Label. The definition of Service yamL is as follows.

kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 9376
Copy the code

Yaml above defines a set of pods with the tag app=MyApp that together form a service called my-Service. Kubernetes supports two modes of service discovery: Environment Variables and DNS.

4. Volumes

We know that the file system in the container is temporary, and once the container is restarted, all run-time operations on the file are lost. Kubernetes used Volumes to solve this problem. Different from Docker volumes, Kubernetes provides Volume lifecycle management and supports multiple storage forms. Specify the volume type and mount location in the Pod spec.

Kubernetes supports the following volume types: awsElasticBlockStore, azureDisk, azureFile, cephfs, configMap, CSI, downwardAPI, emptyDir, FC, local, and NFS.

Add-ons

  • DNS
  • Ingress Controller
  • Heapster
  • Dashboard

The resources

  1. Kubernetes Introduction
  2. Kubernetes Concept
  3. Kubernetes Design and Architecture
  4. StatefulSet: Running and scaling of stateful applications in Kubernetes
  5. Kubernetes DaemonSet resource object
  6. ReplicaSet of Kubernetes object