Pod,Deployment,ReplicaSet,Service Association, Relationship Analysis in k8s

Keywords: Programming MySQL Kubernetes Docker


First, let's start with the smallest dispatch unit, pod.
There is currently a pod in my k8s cluster whose name is 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

Check out the details of the 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/
Start Time:         Fri, 01 Nov 2019 10:57:47 +0800
Labels:             name=mysql
Annotations:        <none>
Status:             Running
Controlled By:      ReplicaSet/admin-mysql-1d29997-5db458497c
    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
      MYSQL_ROOT_PASSWORD:  welcome1
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-9rfpv (ro)
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
    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 ~]# 

Can you see here that a pod is managed by a ReplicaSet named admin-mysql-1d29997-5db458497c, so we think that RS is a higher level component dedicated to managing pods than Pod.An RS manages a batch of pods.

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


Next, we'll look at the details of this 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
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
    Image:      mysql57:5.7
    Port:       3306/TCP
    Host Port:  0/TCP
      MYSQL_ROOT_PASSWORD:  welcome1
    Mounts:                 <none>
  Volumes:                  <none>
Events:                     <none>
[root@k8s-master ~]# 

Grab Key Information
Controlled By: Deployment/admin-mysql-1d29997

This RS is controlled by a Deployment named admin-mysql-1d29997, so Deployment is a component used to manage RS at a higher level than RS.

Events that occur at the RS level are operations on pods, creating pods, deleting pods

Next, let's take a look at 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
    Image:      mysql57:5.7
    Port:       3306/TCP
    Host Port:  0/TCP
      MYSQL_ROOT_PASSWORD:  welcome1
    Mounts:                 <none>
  Volumes:                  <none>
  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 ~]# 

As you can see, at the deployment level, it is no longer controlled by other components, and its state transitions result from being invoked as an API.We see that what happens at the deployment level is generally the creation of a service, the rolling upgrade of a service, or the operation of an RS scaled Pod cluster.

Finally, it is also clear here that quantity is the stable service that service provides to the outside world on this whole set of foundations.

Posted by Salis on Thu, 07 Nov 2019 11:44:27 -0800