This series of articles will be organized into my GitHub repository of the Java Interview Guide. For more highlights, visit my repository

https://github.com/h2pl/Java-Tutorial

If you like, please click Star

This series of articles will be organized on my personal blog:

www.how2playlife.com

This series of posts will introduce common backend technology, it is a kind of comprehensive ability for the back-end engineer, we will gradually understand the search technology, cloud computing technology, the common technology such as research and development of big data is fond of, in order to make you a more complete understanding of the outline of the back-end technology stack, to participate in the development of distributed applications and subsequent learning to prepare.

If you have any suggestions or questions about this series of articles, you can also follow the public account “Java Technology Jianghu” to contact me. You are welcome to participate in the creation and revision of this series of blog posts.

Ten minutes to understand the core concepts of Kubernetes

This article will briefly introduce the core concepts of Kubernetes. Because these definitions can be found in Kubernetes documentation, the article also avoids long, boring paragraphs. Instead, we’ll use some diagrams (some of them animated) and examples to explain these concepts. We found that some concepts, such as services, were difficult to fully understand without the aid of diagrams. We also provide links to Kubernetes documentation where appropriate for further study.

Container features, mirroring, networking; Kubernetes architecture, core components, basic functions; Kubernetes design concept, architecture design, basic functions, common objects, design principles; Kubernetes database, runtime, network, plug-ins have been implemented experience; Microservices architecture, components, monitoring solutions, etc.

Let’s get started.

What is Kubernetes?

Kubernetes (K8S) is an open source platform for automating container operations such as deployment, scheduling, and scaling between node clusters. If you have ever deployed containers using Docker container technology, you can think of Docker as a low-level component used internally by Kubernetes. Kubernetes supports not only Docker but also Rocket, which is another container technology. Using Kubernetes you can:

  • Automates container deployment and replication
  • Expand or shrink the container at any time
  • Organize containers into groups and provide load balancing between containers
  • Easily upgrade to a new version of the application container
  • Provide container elasticity, replace containers if they fail, etc…

In fact, with Kubernetes you can deploy a full cluster of multi-tier containers (front end, back end, etc.) with a single deployment file and a single command:

$ kubectl create -f single-config-file.yaml
Copy the code

Kubectl is a command line program that interacts with the Kubernetes API. Now introduce some core concepts.

The cluster

A cluster is a group of nodes, either physical servers or virtual machines, on which the Kubernetes platform is installed. The following figure shows such a cluster. Note that the diagram is simplified to emphasize the core concepts. A typical Kubernetes architecture diagram can be seen here.

1.png

Above you can see the following components with special ICONS for Service and Label:

  • Pod
  • Container (Container)
  • Label (Label)
  • Replication Controller
  • Service (Service)
  • Node (Node)
  • Kubernetes Master Kubernetes Master

Pod

Pods (the green box above) are arranged on nodes and contain a set of containers and volumes. Containers in the same Pod share the same network namespace and can communicate with each other using localhost. A Pod is transient, not a persistent entity. You may have these questions:

  • If a Pod is ephemeral, how can I persist the container data so that it can survive a restart? Yes, Kubernetes supports the concept of volumes, so persistent volume types can be used.
  • Do you want to create pods manually? If you want to create multiple copies of the same container, do you need to create them individually? You can manually create a single Pod, but you can also create multiple copies using the Pod template using the Replication Controller, as described below.
  • If the Pod is ephemeral, and the IP address may change on reboot, how can you reliably point from the front container to the back container? You can use Service, as described below.

Lable

As the figure shows, some pods have labels. A Label is a key/value pair attached to a Pod that passes user-defined properties. For example, you might create a “tier” and “app” Label, Label (Tier =frontend, app=myapp) to Label the front-end Pod container, and Label (Tier = Backend, app= myApp) to Label the backend Pod. You can then use Selectors to select a Pod with a particular Label and apply a Service or Replication Controller to it.

Replication Controller

Do you want to create Pods manually? If you want to create multiple copies of the same container, do you need to create them individually? Can you add Pods to a logical group?

The Replication Controller ensures that a specified number of Pod “copies” are running at any given time. If a Replication Controller is created for a Pod and three copies are specified, it creates three pods and continuously monitors them. If a Pod does not respond, the Replication Controller replaces it, keeping the total to 3. As shown in the following animation:

2.gif

If the previously unresponsive Pod is recovered, and there are now four, the Replication Controller will terminate one of them to keep the total to three. If the total number of copies is changed to 5 at run time, the Replication Controller immediately starts two new pods, ensuring a total of 5. You can also shrink the Pod in this way, which is useful when performing rolling upgrades.

When creating a Replication Controller, you need to specify two things:

  1. Pod template: The template used to create Pod copies
  2. Label: Label of the Pod that the Replication Controller needs to monitor.

Now that you’ve created some copies of Pod, how do you balance the load on these copies? What we need is Service.

Service

If the Pods are ephemeral, and the IP address may change when you reboot, how can you reliably point from the front-end container to the background container?

A Service is a layer of abstraction that defines a set of pods and the policies that access them. Service finds the Pod group by Label. Because services are abstract, they are often invisible in diagrams, which makes the concept even more difficult to understand.

Now, assume that there are two backend pods and the name of the backend Service is’ backend-service ‘and the lable selector is (tier=backend, app=myapp). Backend-service services do two important things:

  • A DNS entry is created for the Service in the local cluster. Therefore, the front-end Pod only needs the DNS lookup of the host name “backend-service” to resolve the IP address available to the front-end application.
  • Now the front-end has the IP address of the back-end service, but which of the two back-end pods should it access? The Service provides transparent load balancing between the two background Pods, distributing requests to either of them (as shown in the animation below). This is done using a Kube-proxy running on each Node. Here are some more technical details.

The following animation shows the functionality of a Service. Notice how much simplification this diagram makes. If you don’t go into network configuration, the underlying network and routing involved in achieving transparent load balancing goals are relatively advanced. If you are interested, here is a more in-depth introduction.

3.gif

There is a special type of Kubernetes Service called ‘LoadBalancer’ that acts as an external LoadBalancer to balance traffic between a certain number of pods. For example, it is useful for load balancing Web traffic.

Node

Nodes (the orange box above) are physical or virtual machines that act as Kubernetes workers, often referred to as Minion. Each node runs the following Kubernetes key components:

  • Kubelet: is the primary node agent.
  • Kube-proxy: Service uses it to route links to pods, as described above.
  • Docker or Rocket: Container technology used by Kubernetes to create containers.

Kubernetes Master

The cluster has a Kubernetes Master (purple box). Kubernetes Master provides a unique view of the cluster and has a set of components, such as Kubernetes API Server. The API Server provides REST endpoints that you can use to interact with the cluster. The master node includes the Replication Controller for creating and replicating pods.

The next step

Now that we know the basics of Kubernetes’ core concepts, you can read the Kubernetes user manual further. User manuals provide quick and complete documentation for learning. If you can’t wait to try Kubernetes, you can use Google Container Engine. Google Container Engine is a hosted Kubernetes Container environment. After a simple registration/login, you can try the examples above.

Learn the Kubernetes Key Concepts in 10 Minutes Cui Jingwen (===========================) is a senior software engineer at IBM, responsible for system testing of IBM WebSphere business process management software. Once worked for VMware, engaged in quality assurance of desktop virtualization products. Strong interest in virtualization, middleware technology, business process management.