Docker+kubernetes (k8s) micro-service container Practice

Source: Internet
Author: User
Tags dns entry k8s

Docker+kubernetes (k8s) micro-service container Practice

": HTTPS://PAN.BAIDU.COM/S/16RTL8DBMFUWJKEKZRD9EMW"

Let's get started.
What is Kubernetes?
Kubernetes (k8s) is an open source platform for automating container operations, including deployment, scheduling, and Inter-node cluster expansion. If you've ever used Docker container technology to deploy containers, you can consider Docker as a low-level component used internally by Kubernetes. Kubernetes not only supports Docker, it also supports rocket, which is another container technology.
Use Kubernetes to:
Deployment and replication of automated containers
Expand or shrink container size at any time
Organize containers into groups and provide load balancing between containers
The new version of the application container is easy to upgrade
Provide container elasticity, replace it if the container fails, etc...

In fact, using kubernetes requires only a single deployment file, with a single command to deploy a full cluster of multi-tier containers (front end, background, etc.):
$ kubectl create-f Single-config-file.yaml

Kubectl is a command-line program that interacts with the Kubernetes API. Here are some core concepts.
Cluster
A cluster is a set of nodes that can be physical servers or virtual machines, with the Kubernetes platform installed on top of them. Demonstrate such a cluster. Note that the diagram is designed to emphasize the simplification of core concepts. Here you can see a typical kubernetes architecture diagram.

You can see the following components, which represent service and label with special icons:
Pod
Container (Container)
Label (label)
Replication controller (Replication controllers)
Service (enter image description here) (services)
Node (nodes)
Kubernetes Master (Kubernetes master node)

Pod
The Pod (green box) is arranged on the node and contains a set of containers and volumes. Containers in the same pod share the same network namespace, and you can use localhost to communicate with one another. Pods are short-lived, not persistent entities. You may have these questions:
If the pod is ephemeral, how can I persist the container data so that it can exist across reboots? Yes, Kubernetes supports the concept of volumes, so you can use persisted volume types.
Do you want to create pods manually, and create multiple copies of the same container separately? You can create a single pod manually, but you can also use the replication controller to create multiple copies using the Pod template, which is described in more detail below.
If the pod is ephemeral, then the IP address may change when restarting, so how can you point to the backend container correctly and reliably from the front-end container? You can use the service at this point, which is described in more detail below.

lable
Positive, some pods have a label (enter image description here). A label is a pair of key/value pairs attach to the pod that is used to pass user-defined properties. For example, you might create a "tier" and "app" tag, mark the front pod container with a label (Tier=frontend, App=myapp), and tag the background pod with a label (Tier=backend, App=myapp). You can then use selectors to select the pod with a specific label and apply the service or replication controller to the above.
Replication Controller
Do you want to create the pod manually, and create multiple copies of the same container, each of which can be pods into a logical group?

The Replication controller ensures that a specified number of pod "replicas" are running at any time. If you create a replication controller for a pod and specify 3 copies, it creates 3 pods and continuously monitors them. If a pod does not respond, the replication controller replaces it and maintains a total of 3. As shown in the following animation:

If the previously unresponsive pod is restored and there are now 4 pods, then the replication controller will keep the total of one of the stops at 3. If you change the total number of replicas to 5,replication controller in the run, 2 new pods will be started immediately, with a guaranteed total of 5. You can also narrow the pod in such a way that this feature is useful when performing a rolling upgrade.

When creating a replication controller, you need to specify two things:
Pod Template: A template to create a copy of the pod
The label:replication controller needs to monitor the label of the pod.

Now that you have created some copies of the pod, how do you balance the load on those replicas? What we need is the service.
Service
If the pods is short-lived, then the IP address may change on reboot, how can the front-end container correctly and reliably point to the background container?

A service is a layer of abstraction that defines a series of pods and the strategy to access them. The service uses the label to locate the pod group. Because the service is abstract, it is often not visible in the chart, which makes the concept even more difficult to understand.

Now, suppose there are 2 background pods, and the name of the background service is defined as ' Backend-service ' and the lable selector is (Tier=backend, App=myapp). Backend-service's service will do the following two important things:
A DNS entry for the local cluster is created for the service, so the front-end pod only needs the DNS lookup host named ' Backend-service ' to resolve the IP address available to the front-end application.
Now the frontend has got the IP address of the background service, but which one of the 2 background pods should be accessed? The service provides transparent load balancing between the 2 background pods, distributing the request to any one of them (as shown in the following animation). Completed by the agent running on each node (kube-proxy). More technical details are available here.

There is a special type of kubernetes service called ' LoadBalancer ', which is used as an external load balancer to equalize traffic between a certain number of pods. For example, it is useful for load-balanced web traffic.
Node
A node (orange box) is a physical or virtual machine, as a kubernetes worker, often referred to as Minion. Each node runs the following kubernetes key components:
Kubelet: Is the master node agent.
Kube-proxy:service uses it to route links to the pod, as described above.
The container technology used by Docker or rocket: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 range of components, such as Kubernetes API Server. API Server provides a rest endpoint that you can use to set XXX to each other. The master node includes the replication Controller used to create and copy pods.

Docker+kubernetes (k8s) micro-service container Practice

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.