您现在的位置是:首页 >学无止境 >研发工程师玩转Kubernetes——使用Deployment进行版本升级网站首页学无止境

研发工程师玩转Kubernetes——使用Deployment进行版本升级

breaksoftware 2024-06-17 11:28:19
简介研发工程师玩转Kubernetes——使用Deployment进行版本升级

软件升级是一件非常常见的事,本节我们将尝试使用Deployment进行软件升级。

更新simple_http版本

我们还是借助《研发工程师玩转Kubernetes——构建、推送自定义镜像》中的代码库,只是稍微修改一下Dockerfile——将版本变成2。

From python:3.11
RUN pip install --upgrade pip
COPY requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
COPY main.py /main.py
CMD ["python","main.py","-port","8888","-version","2"]

在这里插入图片描述

构建镜像

docker build -t simple_http:v2 .
Sending build context to Docker daemon  16.25MB
Step 1/6 : From python:3.11
 ---> 815c8c75dfc0
Step 2/6 : RUN pip install --upgrade pip
 ---> Using cache
 ---> e26af84d8b3e
Step 3/6 : COPY requirements.txt /requirements.txt
 ---> Using cache
 ---> 9e14379efd70
Step 4/6 : RUN pip install -r /requirements.txt
 ---> Using cache
 ---> 964f97edf3b5
Step 5/6 : COPY main.py /main.py
 ---> Using cache
 ---> 183ac054cd4d
Step 6/6 : CMD ["python","main.py","-port","8888","-version","2"]
 ---> Running in 1fc7e3afb2c9
Removing intermediate container 1fc7e3afb2c9
 ---> 57ab1ae7f5de
Successfully built 57ab1ae7f5de
Successfully tagged simple_http:v2

推送镜像

docker tag simple_http:v2 localhost:32000/simple_http:v2
docker push localhost:32000/simple_http:v2

上线老版本

直接借用《研发工程师玩转Kubernetes——使用Deployment进行多副本维护》的案例。具体请转到这篇文章。只要部署了2个Pod即可。
使用下面指令查看Pod

kubectl describe pod
Name:             simple-http-deployment-5995f574dc-lzs8v
Namespace:        default
Priority:         0
Service Account:  default
Node:             fangliang-virtual-machine/172.30.45.36
Start Time:       Mon, 22 May 2023 21:27:01 +0800
Labels:           app=simple_http
                  pod-template-hash=5995f574dc
Annotations:      cni.projectcalico.org/containerID: 311e41d76878cb77546a754ad1123556a58c3b3b3ea087634d80dcf6f12240e8
                  cni.projectcalico.org/podIP: 10.1.62.150/32
                  cni.projectcalico.org/podIPs: 10.1.62.150/32
Status:           Running
IP:               10.1.62.150
IPs:
  IP:           10.1.62.150
Controlled By:  ReplicaSet/simple-http-deployment-5995f574dc
Containers:
  simple-http-container:
    Container ID:   containerd://5f722b33ba614ae1c4351567e0fb07946cb26b8529d55ab1ca9168f1af4563b8
    Image:          localhost:32000/simple_http:v1
    Image ID:       localhost:32000/simple_http@sha256:cbee584f83426593efb95a9e2213bb40143a1c86c3d217e65d30430033f846d4
    Port:           8888/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Mon, 22 May 2023 21:27:03 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-62cr6 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-62cr6:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  22s   default-scheduler  Successfully assigned default/simple-http-deployment-5995f574dc-lzs8v to fangliang-virtual-machine
  Normal  Pulled     22s   kubelet            Container image "localhost:32000/simple_http:v1" already present on machine
  Normal  Created    22s   kubelet            Created container simple-http-container
  Normal  Started    21s   kubelet            Started container simple-http-container


Name:             simple-http-deployment-5995f574dc-l7zwv
Namespace:        default
Priority:         0
Service Account:  default
Node:             fangliang-virtual-machine/172.30.45.36
Start Time:       Mon, 22 May 2023 21:27:01 +0800
Labels:           app=simple_http
                  pod-template-hash=5995f574dc
Annotations:      cni.projectcalico.org/containerID: 613a62e30933c3715b43de4e83ccf1baa93e53ac1434cf63dd93178a5214c992
                  cni.projectcalico.org/podIP: 10.1.62.149/32
                  cni.projectcalico.org/podIPs: 10.1.62.149/32
Status:           Running
IP:               10.1.62.149
IPs:
  IP:           10.1.62.149
Controlled By:  ReplicaSet/simple-http-deployment-5995f574dc
Containers:
  simple-http-container:
    Container ID:   containerd://e52726f94486008b8bd375e0dac3243ad534186ea63d7ca5ae522c68fb05d89a
    Image:          localhost:32000/simple_http:v1
    Image ID:       localhost:32000/simple_http@sha256:cbee584f83426593efb95a9e2213bb40143a1c86c3d217e65d30430033f846d4
    Port:           8888/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Mon, 22 May 2023 21:27:03 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-5hpdv (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-5hpdv:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  22s   default-scheduler  Successfully assigned default/simple-http-deployment-5995f574dc-l7zwv to fangliang-virtual-machine
  Normal  Pulled     22s   kubelet            Container image "localhost:32000/simple_http:v1" already present on machine
  Normal  Created    22s   kubelet            Created container simple-http-container
  Normal  Started    21s   kubelet            Started container simple-http-container

可以看到两个Pod(simple-http-deployment-5995f574dc-lzs8v和simple-http-deployment-5995f574dc-l7zwv)对应的Image都是localhost:32000/simple_http:v1。

查看Deployment

kubectl describe deployments.apps simple-http-deployment 
Name:                   simple-http-deployment
Namespace:              default
CreationTimestamp:      Mon, 22 May 2023 21:27:01 +0800
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=simple_http
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=simple_http
  Containers:
   simple-http-container:
    Image:        localhost:32000/simple_http:v1
    Port:         8888/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   simple-http-deployment-5995f574dc (2/2 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  3m16s  deployment-controller  Scaled up replica set simple-http-deployment-5995f574dc to 2

此时我们看到该Deployment管理的ReplicaSet是simple-http-deployment-5995f574dc。

更新

kubectl set image deployments/simple-http-deployment simple-http-container=localhost:32000/simple_http:v2

deployment.apps/simple-http-deployment image updated

我们查看下Pod

Name:             simple-http-deployment-576c865db-k48mn
Namespace:        default
Priority:         0
Service Account:  default
Node:             fangliang-virtual-machine/172.30.45.36
Start Time:       Mon, 22 May 2023 21:32:16 +0800
Labels:           app=simple_http
                  pod-template-hash=576c865db
Annotations:      cni.projectcalico.org/containerID: e35c8331fb45eeef955671d86bcd5156082246875362f2a87b87ac8be05fdfe6
                  cni.projectcalico.org/podIP: 10.1.62.147/32
                  cni.projectcalico.org/podIPs: 10.1.62.147/32
Status:           Running
IP:               10.1.62.147
IPs:
  IP:           10.1.62.147
Controlled By:  ReplicaSet/simple-http-deployment-576c865db
Containers:
  simple-http-container:
    Container ID:   containerd://ffe70fe17696d901bb2a460469ae318bccfac95e0fe6f0ca0e157308641615d1
    Image:          localhost:32000/simple_http:v2
    Image ID:       localhost:32000/simple_http@sha256:213ba4174b3afac02b48af19258c03b32a426d31ca27742e05aacea7a7a6edc1
    Port:           8888/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Mon, 22 May 2023 21:32:18 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-5z9dp (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-5z9dp:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  38s   default-scheduler  Successfully assigned default/simple-http-deployment-576c865db-k48mn to fangliang-virtual-machine
  Normal  Pulling    38s   kubelet            Pulling image "localhost:32000/simple_http:v2"
  Normal  Pulled     38s   kubelet            Successfully pulled image "localhost:32000/simple_http:v2" in 119.472724ms (119.476524ms including waiting)
  Normal  Created    38s   kubelet            Created container simple-http-container
  Normal  Started    37s   kubelet            Started container simple-http-container


Name:             simple-http-deployment-576c865db-bjwns
Namespace:        default
Priority:         0
Service Account:  default
Node:             fangliang-virtual-machine/172.30.45.36
Start Time:       Mon, 22 May 2023 21:32:18 +0800
Labels:           app=simple_http
                  pod-template-hash=576c865db
Annotations:      cni.projectcalico.org/containerID: 11f76fe799f1b5a3d4899305e9443d2bcedc5f815c28c8c44f8664f93cc150e4
                  cni.projectcalico.org/podIP: 10.1.62.156/32
                  cni.projectcalico.org/podIPs: 10.1.62.156/32
Status:           Running
IP:               10.1.62.156
IPs:
  IP:           10.1.62.156
Controlled By:  ReplicaSet/simple-http-deployment-576c865db
Containers:
  simple-http-container:
    Container ID:   containerd://2459b017ee5fb29ac61f488ffc0eabb0016f5a18bf6b031345480d9d2fb3c84a
    Image:          localhost:32000/simple_http:v2
    Image ID:       localhost:32000/simple_http@sha256:213ba4174b3afac02b48af19258c03b32a426d31ca27742e05aacea7a7a6edc1
    Port:           8888/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Mon, 22 May 2023 21:32:19 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-4lp5j (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-4lp5j:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  37s   default-scheduler  Successfully assigned default/simple-http-deployment-576c865db-bjwns to fangliang-virtual-machine
  Normal  Pulled     36s   kubelet            Container image "localhost:32000/simple_http:v2" already present on machine
  Normal  Created    36s   kubelet            Created container simple-http-container
  Normal  Started    36s   kubelet            Started container simple-http-container

老的Pod(simple-http-deployment-5995f574dc-lzs8v和simple-http-deployment-5995f574dc-l7zwv)被删除了,新的Pod( simple-http-deployment-576c865db-k48mn和simple-http-deployment-576c865db-bjwns)被创建出来。

查看ReplicaSet

kubectl describe replicasets.apps 
Name:           simple-http-deployment-576c865db
Namespace:      default
Selector:       app=simple_http,pod-template-hash=576c865db
Labels:         app=simple_http
                pod-template-hash=576c865db
Annotations:    deployment.kubernetes.io/desired-replicas: 2
                deployment.kubernetes.io/max-replicas: 3
                deployment.kubernetes.io/revision: 2
Controlled By:  Deployment/simple-http-deployment
Replicas:       2 current / 2 desired
Pods Status:    2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=simple_http
           pod-template-hash=576c865db
  Containers:
   simple-http-container:
    Image:        localhost:32000/simple_http:v2
    Port:         8888/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulCreate  97s   replicaset-controller  Created pod: simple-http-deployment-576c865db-k48mn
  Normal  SuccessfulCreate  95s   replicaset-controller  Created pod: simple-http-deployment-576c865db-bjwns


Name:           simple-http-deployment-5995f574dc
Namespace:      default
Selector:       app=simple_http,pod-template-hash=5995f574dc
Labels:         app=simple_http
                pod-template-hash=5995f574dc
Annotations:    deployment.kubernetes.io/desired-replicas: 2
                deployment.kubernetes.io/max-replicas: 3
                deployment.kubernetes.io/revision: 1
Controlled By:  Deployment/simple-http-deployment
Replicas:       0 current / 0 desired
Pods Status:    0 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=simple_http
           pod-template-hash=5995f574dc
  Containers:
   simple-http-container:
    Image:        localhost:32000/simple_http:v1
    Port:         8888/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulDelete  95s   replicaset-controller  Deleted pod: simple-http-deployment-5995f574dc-l7zwv
  Normal  SuccessfulDelete  93s   replicaset-controller  Deleted pod: simple-http-deployment-5995f574dc-lzs8v

可以看到老的ReplicaSet在删除老Pod,新的则创建了新的Pod。
再过段时间执行上述命令,可以看到老的ReplicaSet并没有被删除。

Name:           simple-http-deployment-576c865db
Namespace:      default
Selector:       app=simple_http,pod-template-hash=576c865db
Labels:         app=simple_http
                pod-template-hash=576c865db
Annotations:    deployment.kubernetes.io/desired-replicas: 2
                deployment.kubernetes.io/max-replicas: 3
                deployment.kubernetes.io/revision: 2
Controlled By:  Deployment/simple-http-deployment
Replicas:       2 current / 2 desired
Pods Status:    2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=simple_http
           pod-template-hash=576c865db
  Containers:
   simple-http-container:
    Image:        localhost:32000/simple_http:v2
    Port:         8888/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:           <none>


Name:           simple-http-deployment-5995f574dc
Namespace:      default
Selector:       app=simple_http,pod-template-hash=5995f574dc
Labels:         app=simple_http
                pod-template-hash=5995f574dc
Annotations:    deployment.kubernetes.io/desired-replicas: 2
                deployment.kubernetes.io/max-replicas: 3
                deployment.kubernetes.io/revision: 1
Controlled By:  Deployment/simple-http-deployment
Replicas:       0 current / 0 desired
Pods Status:    0 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=simple_http
           pod-template-hash=5995f574dc
  Containers:
   simple-http-container:
    Image:        localhost:32000/simple_http:v1
    Port:         8888/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:           <none>

查看Deployment更新后信息

kubectl describe deployments.apps 
Name:                   simple-http-deployment
Namespace:              default
CreationTimestamp:      Mon, 22 May 2023 21:27:01 +0800
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 2
Selector:               app=simple_http
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=simple_http
  Containers:
   simple-http-container:
    Image:        localhost:32000/simple_http:v2
    Port:         8888/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   simple-http-deployment-576c865db (2/2 replicas created)
Events:          <none>

可以看到NewReplicaSet被更新为新的ReplicaSet simple-http-deployment-576c865db 。老的ReplicaSet simple-http-deployment-5995f574dcz在这儿没有体现。

回滚

 kubectl rollout undo deployment simple-http-deployment

deployment.apps/simple-http-deployment rolled back

查看Deployment

kubectl describe deployments.apps
Name:                   simple-http-deployment
Namespace:              default
CreationTimestamp:      Mon, 22 May 2023 21:27:01 +0800
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 3
Selector:               app=simple_http
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=simple_http
  Containers:
   simple-http-container:
    Image:        localhost:32000/simple_http:v1
    Port:         8888/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   simple-http-deployment-5995f574dc (2/2 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  4s    deployment-controller  Scaled up replica set simple-http-deployment-5995f574dc to 1 from 0
  Normal  ScalingReplicaSet  3s    deployment-controller  Scaled down replica set simple-http-deployment-576c865db to 1 from 2
  Normal  ScalingReplicaSet  3s    deployment-controller  Scaled up replica set simple-http-deployment-5995f574dc to 2 from 1
  Normal  ScalingReplicaSet  1s    deployment-controller  Scaled down replica set simple-http-deployment-576c865db to 0 from 1

可以看到最开始V1版本对应的ReplicaSet simple-http-deployment-5995f574dc又被启用,镜像也变成了三个版本localhost:32000/simple_http:v1。

查看ReplicaSet

kubectl describe replicasets.apps 
Name:           simple-http-deployment-5995f574dc
Namespace:      default
Selector:       app=simple_http,pod-template-hash=5995f574dc
Labels:         app=simple_http
                pod-template-hash=5995f574dc
Annotations:    deployment.kubernetes.io/desired-replicas: 2
                deployment.kubernetes.io/max-replicas: 3
                deployment.kubernetes.io/revision: 3
                deployment.kubernetes.io/revision-history: 1
Controlled By:  Deployment/simple-http-deployment
Replicas:       2 current / 2 desired
Pods Status:    2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=simple_http
           pod-template-hash=5995f574dc
  Containers:
   simple-http-container:
    Image:        localhost:32000/simple_http:v1
    Port:         8888/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulCreate  24s   replicaset-controller  Created pod: simple-http-deployment-5995f574dc-6dmtt
  Normal  SuccessfulCreate  23s   replicaset-controller  Created pod: simple-http-deployment-5995f574dc-547sp


Name:           simple-http-deployment-576c865db
Namespace:      default
Selector:       app=simple_http,pod-template-hash=576c865db
Labels:         app=simple_http
                pod-template-hash=576c865db
Annotations:    deployment.kubernetes.io/desired-replicas: 2
                deployment.kubernetes.io/max-replicas: 3
                deployment.kubernetes.io/revision: 2
Controlled By:  Deployment/simple-http-deployment
Replicas:       0 current / 0 desired
Pods Status:    2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=simple_http
           pod-template-hash=576c865db
  Containers:
   simple-http-container:
    Image:        localhost:32000/simple_http:v2
    Port:         8888/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulDelete  23s   replicaset-controller  Deleted pod: simple-http-deployment-576c865db-bjwns
  Normal  SuccessfulDelete  21s   replicaset-controller  Deleted pod: simple-http-deployment-576c865db-k48mn

可以看到V2版本对应的ReplicaSet还存在。
这是否意味着再次回滚又会回滚到V2呢?是的。

再回滚

再将kubectl rollout undo deployment simple-http-deployment执行一遍,可以发现Deployment又启用了V2版本对应的simple-http-deployment-576c865db,弃用了V1版本对应的simple-http-deployment-5995f574dc。

kubectl describe replicasets.apps
Name:           simple-http-deployment-576c865db
Namespace:      default
Selector:       app=simple_http,pod-template-hash=576c865db
Labels:         app=simple_http
                pod-template-hash=576c865db
Annotations:    deployment.kubernetes.io/desired-replicas: 2
                deployment.kubernetes.io/max-replicas: 3
                deployment.kubernetes.io/revision: 4
                deployment.kubernetes.io/revision-history: 2
Controlled By:  Deployment/simple-http-deployment
Replicas:       2 current / 2 desired
Pods Status:    2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=simple_http
           pod-template-hash=576c865db
  Containers:
   simple-http-container:
    Image:        localhost:32000/simple_http:v2
    Port:         8888/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulCreate  8s    replicaset-controller  Created pod: simple-http-deployment-576c865db-qm5gp
  Normal  SuccessfulCreate  7s    replicaset-controller  Created pod: simple-http-deployment-576c865db-bzbbw


Name:           simple-http-deployment-5995f574dc
Namespace:      default
Selector:       app=simple_http,pod-template-hash=5995f574dc
Labels:         app=simple_http
                pod-template-hash=5995f574dc
Annotations:    deployment.kubernetes.io/desired-replicas: 2
                deployment.kubernetes.io/max-replicas: 3
                deployment.kubernetes.io/revision: 3
                deployment.kubernetes.io/revision-history: 1
Controlled By:  Deployment/simple-http-deployment
Replicas:       0 current / 0 desired
Pods Status:    2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=simple_http
           pod-template-hash=5995f574dc
  Containers:
   simple-http-container:
    Image:        localhost:32000/simple_http:v1
    Port:         8888/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulDelete  7s    replicaset-controller  Deleted pod: simple-http-deployment-5995f574dc-6dmtt
  Normal  SuccessfulDelete  5s    replicaset-controller  Deleted pod: simple-http-deployment-5995f574dc-547sp

通过这次实验,我们就更好理解Deployment是如何使用ReplicaSet来做版本管理的了。
在这里插入图片描述

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。