k8s 中Pod,Deployment,ReplicaSet,Service关联、关系分析

# 分析

pod
首先,我们先从最小的调度单位pod开始。
我的k8s集群中目前有一个pod,它的name为admin-mysql-1d29997-5db458497c-h6rrs

[root@k8s-master ~]# kubectl get pod admin-mysql-1d29997-5db458497c-h6rrs
NAME                                   READY   STATUS    RESTARTS   AGE
admin-mysql-1d29997-5db458497c-h6rrs   1/1     Running   0          5d23h

查看一下pod的详细内容:

[root@k8s-master ~]# kubectl describe pod admin-mysql-1d29997-5db458497c-h6rrs
Name:               admin-mysql-1d29997-5db458497c-h6rrs
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               k8s-node1/192.168.0.247
Start Time:         Fri, 01 Nov 2019 10:57:47 +0800
Labels:             name=mysql
                    pod-template-hash=5db458497c
Annotations:        <none>
Status:             Running
IP:                 10.244.1.72
Controlled By:      ReplicaSet/admin-mysql-1d29997-5db458497c
Containers:
  mysql57-container:
    Container ID:   docker://7e68cae8d4e9840ed908965252ae7aff8281ca81954ab0b5d58e053f5371bb5d
    Image:          mysql57:5.7
    Image ID:       docker://sha256:f6509bac49801f48628167728aba66d64533aaa7d384e03b75a8fe4e6c0f6599
    Port:           3306/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Fri, 01 Nov 2019 10:57:48 +0800
    Ready:          True
    Restart Count:  0
    Environment:
      MYSQL_ROOT_PASSWORD:  welcome1
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-9rfpv (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-9rfpv:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-9rfpv
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:          <none>
[root@k8s-master ~]# 

在这里能看到吗,pod是被一个名字为admin-mysql-1d29997-5db458497c的ReplicaSet管理的,所以我们认为,RS是比Pod高一级别的专门用来管理pod的组件。一个RS会管理一批pod。

Controlled By: ReplicaSet/admin-mysql-1d29997-5db458497c

ReplicateSet(rs)

接下来,我们就看看这个RS的详细情况

[root@k8s-master ~]# kubectl describe rs admin-mysql-1d29997-5db458497c
Name:           admin-mysql-1d29997-5db458497c
Namespace:      default
Selector:       name=mysql,pod-template-hash=5db458497c
Labels:         name=mysql
                pod-template-hash=5db458497c
Annotations:    deployment.kubernetes.io/desired-replicas: 1
                deployment.kubernetes.io/max-replicas: 2
                deployment.kubernetes.io/revision: 1
Controlled By:  Deployment/admin-mysql-1d29997
Replicas:       1 current / 1 desired
Pods Status:    1 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  name=mysql
           pod-template-hash=5db458497c
  Containers:
   mysql57-container:
    Image:      mysql57:5.7
    Port:       3306/TCP
    Host Port:  0/TCP
    Environment:
      MYSQL_ROOT_PASSWORD:  welcome1
    Mounts:                 <none>
  Volumes:                  <none>
Events:                     <none>
[root@k8s-master ~]# 

抓住关键信息
Controlled By: Deployment/admin-mysql-1d29997

这个RS被名字为admin-mysql-1d29997的Deployment控制,这样看,Deployment是比RS高一级别用于管理RS的组件。

在RS级别上发生的事件,均是对pod的操作,创建pod,删除pod

Deployment
接下来,我们来看看Delpoyment

[root@k8s-master ~]# kubectl describe deploy admin-mysql-1d29997
Name:                   admin-mysql-1d29997
Namespace:              default
CreationTimestamp:      Fri, 01 Nov 2019 10:57:46 +0800
Labels:                 name=mysql
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               name=mysql
Replicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  name=mysql
  Containers:
   mysql57-container:
    Image:      mysql57:5.7
    Port:       3306/TCP
    Host Port:  0/TCP
    Environment:
      MYSQL_ROOT_PASSWORD:  welcome1
    Mounts:                 <none>
  Volumes:                  <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   admin-mysql-1d29997-5db458497c (1/1 replicas created)
Events:          <none>
[root@k8s-master ~]# 

可以看出,在deployment级别上,不再受其他组件的控制,而他的状态的转变是作为API被调用而产生的。我们看到,在deployment级别上发生的事件一般是创建服务、滚动升级一个服务,或者是操作RS伸缩Pod集群。

service
最后,到这里也很明白量,service其实是在这一整套基础之上提供给外部的稳定的服务。

猜你喜欢

转载自blog.51cto.com/1345992/2448398