The relationship between the Pod, ReplicaSet, Deployment, Service Kubernetes resource object

The relationship between the Pod, ReplicaSet, Deployment, Service following FIG.

Under:

Pod are combinations of one or more containers, these containers shared memory, and the network name space, how to run and regulate. Pod Kubernetes is the smallest unit that can be deployed. Chinese is translated word Pod peas, docker container is like running in a pea pod beans.

ReplicaSet:
Let me talk Replication Controller. Replication Controller role is to ensure Pod run as the number of copies specified.
ReplicaSet Replication Controller is an upgraded version. The only difference between ReplicaSet and Replication Controller support for selectors. Replication Controller supports only equation-based selector (env = dev or environment! = Qa), but ReplicaSet also supports the new, based on the collection selector (version in (v1.0, v2.0) or env notin (dev, qa )).
In yaml file number of copies spec.replicas statement by the pod.

The Deployment:
the Deployment for managing Pod, ReplicaSet, rolling upgrade and rollback may be implemented applications, expansion and volume reduction.

Service:
Just a question, ReplicaSet defines the number of pod is 2, when a pod for some reason stopped, ReplicaSet creates a new pod, pod number in order to ensure that the operation is always 2. But each pod has its own ip, front-end request does not know what the new pod ip is how that request is sent to the front end of the new pod in it?
The answer is to use Service
K8S of Service defines access entry address of a service, a set of cluster instance of Pod copy consisting application distal access behind by the entry address access request from outside the respective container is load balancing to the rear end of the applications. Between the Service and its back-end Pod copy of the cluster is achieved by associating Label Selector.
Please speak human: front-end request is not sent directly to the Pod, but sent to the Service, Service then forwards the request to the pod.

To summarize: Pod is ReplicaSet management, ReplicaSet control the number of pod; ReplicaSet been Deployment Management, Deployment control pod to upgrade applications, rollback, of course, can also control the number of pod. Service provides a unified fixed entrance, front-end responsible for forwarding the request to the Pod.

Practice

Define a myapp.yaml file

apiVersion: apps/v1
# 声明一个Deployment资源对象
kind: Deployment
metadata:
  name: deployment-myapp
spec:
# 通过replicas声明pod个数是2  
  replicas: 2
# 通过标签选择被控制的pod    
  selector:
    matchLabels:
      app: myapp
# 在template中定义pod      
  template:
    metadata:
# 给pod打上标签app=myapp    
      labels:
        app: myapp
    spec:
      containers:
# 声明容器名称,注意不是pod名称,pod名称应该定义在metadata中
      - name: myapp
        image: ikubernetes/myapp:v1
        ports:
        - name: http
          containerPort: 80
# 在一个yaml文件中通过---分割多个资源对象          
---
apiVersion: v1
# 声明一个Service资源对象
kind: Service
metadata:
  name: service-myapp
spec:
# service-myapp将选择标签包含app=myapp的pod
  selector:
    app: myapp
  ports:
  - name: http
# Service监听端口  
    port: 80
# 转发到后端Pod的端口号   
    targetPort: 80

This resource deployment list 

kubectl apply -f myapp.yaml

Look at a very interesting picture

myapp.yaml file declares the name of the deployment, no statement ReplicaSet, the name of the Pod. But kubernetes will automatically give ReplicaSet, Pod from the name.

Deployment name is deployment-myapp

ReplicaSet name is deployment-myapp-5fdb5f69f, actually Deployment name plus hash value of the pod-template

Pod name deployment-myapp-5fdb5f69f-njrb6, deployment-myapp-5fdb5f69f-whpwg, actually the name of a hash value plus ReplicaSet.

Use kubectl describe svc service-myapp Command Details of service-myapp look.

You can see the service-myapp ip address is 10.97.41.88. Sending a request will be forwarded to 10.97.41.88:80 10.244.1.5:80 or 10.244.2.2:80

Look:

hostname first direct request pod, the pod acquisition

curl 10.244.1.5:80/hostname.html

curl 10.244.2.2:80/hostname.html

Then requests service-myapp, service-myapp pod will load request to the backend

curl 10.97.41.88:80/hostname.html

 

There is also a very interesting thing. pod can ping, but did not ping servic

Why is this?

Answer: Because the Service is actually forwarding rules iptables or ipvs, which rules do not support ICMP protocol, so the ping fails slightly.

 

 

 

 

 

 

Published 51 original articles · won praise 14 · views 40000 +

Guess you like

Origin blog.csdn.net/u010606397/article/details/90752262