k8s 更新应用程序

参考:https://kubernetes.io/docs/tutorials/kubernetes-basics/

更新应用程序

用户希望应用程序始终可用,开发人员每天需要部署几次新版本的应用程序。在Kubernetes中,这是通过滚动更新完成的。滚动更新允许部署的更新在零停机时间的情况下进行,方法是用新实例增量地更新Pods实例。新的PODS将安排在有可用资源的节点上。

步骤1:更新应用程序的版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
$ kubectl get deployments
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   4/4     4            4           2m4s
$ kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-6bf84cb898-7fgv8   1/1     Running   0          2m1s
kubernetes-bootcamp-6bf84cb898-t9slq   1/1     Running   0          2m1s
kubernetes-bootcamp-6bf84cb898-tvlw7   1/1     Running   0          2m1s
kubernetes-bootcamp-6bf84cb898-zqfj6   1/1     Running   0          2m
$ kubectl describe pods
Name:               kubernetes-bootcamp-6bf84cb898-7fgv8
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:12:34 +0000
Labels:             pod-template-hash=6bf84cb898
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.4
Controlled By:      ReplicaSet/kubernetes-bootcamp-6bf84cb898
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://8a63d8f20c262c6ac85509c068b98f3c75074ea51511734310616cc312a23c6d
    Image:          gcr.io/google-samples/kubernetes-bootcamp:v1  #镜像版本
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:0d6b8ee63bb57c5f5b6156f446b3bc3b3c143d233037f3a2f00e279c8fcc64af
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:12:35 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  2m24s  default-scheduler  Successfully assigned default/kubernetes-bootcamp-6bf84cb898-7fgv8 to minikube
  Normal  Pulled     2m24s  kubelet, minikube  Container image "gcr.io/google-samples/kubernetes-bootcamp:v1" already present on machine
  Normal  Created    2m24s  kubelet, minikube  Created container
  Normal  Started    2m23s  kubelet, minikube  Started container
 
 
Name:               kubernetes-bootcamp-6bf84cb898-t9slq
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:12:34 +0000
Labels:             pod-template-hash=6bf84cb898
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.7
Controlled By:      ReplicaSet/kubernetes-bootcamp-6bf84cb898
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://926024b884fc353705a542dcef5d6b3ddf0c0dd0c43ef32f1e95a95391f65175
    Image:          gcr.io/google-samples/kubernetes-bootcamp:v1
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:0d6b8ee63bb57c5f5b6156f446b3bc3b3c143d233037f3a2f00e279c8fcc64af
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:12:37 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  2m24s  default-scheduler  Successfully assigned default/kubernetes-bootcamp-6bf84cb898-t9slq to minikube
  Normal  Pulled     2m22s  kubelet, minikube  Container image "gcr.io/google-samples/kubernetes-bootcamp:v1" already present on machine
  Normal  Created    2m22s  kubelet, minikube  Created container
  Normal  Started    2m21s  kubelet, minikube  Started container
 
 
Name:               kubernetes-bootcamp-6bf84cb898-tvlw7
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:12:34 +0000
Labels:             pod-template-hash=6bf84cb898
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.6
Controlled By:      ReplicaSet/kubernetes-bootcamp-6bf84cb898
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://6e47947b7ce2d7295140e4d431901467a452e6e4fcb5226373cc237215831706
    Image:          gcr.io/google-samples/kubernetes-bootcamp:v1
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:0d6b8ee63bb57c5f5b6156f446b3bc3b3c143d233037f3a2f00e279c8fcc64af
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:12:37 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  2m25s  default-scheduler  Successfully assigned default/kubernetes-bootcamp-6bf84cb898-tvlw7 to minikube
  Normal  Pulled     2m23s  kubelet, minikube  Container image "gcr.io/google-samples/kubernetes-bootcamp:v1" already present on machine
  Normal  Created    2m22s  kubelet, minikube  Created container
  Normal  Started    2m21s  kubelet, minikube  Started container
 
 
Name:               kubernetes-bootcamp-6bf84cb898-zqfj6
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:12:34 +0000
Labels:             pod-template-hash=6bf84cb898
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.5
Controlled By:      ReplicaSet/kubernetes-bootcamp-6bf84cb898
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://00cc46214182153a7eae9046041d5b3687c133799561064b0ee1bbaca7e48b11
    Image:          gcr.io/google-samples/kubernetes-bootcamp:v1  #镜像版本
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:0d6b8ee63bb57c5f5b6156f446b3bc3b3c143d233037f3a2f00e279c8fcc64af
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:12:37 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  2m24s  default-scheduler  Successfully assigned default/kubernetes-bootcamp-6bf84cb898-zqfj6 to minikube
  Normal  Pulled     2m23s  kubelet, minikube  Container image "gcr.io/google-samples/kubernetes-bootcamp:v1" already present on machine
  Normal  Created    2m22s  kubelet, minikube  Created container
  Normal  Started    2m21s  kubelet, minikube  Started container

若要将应用程序的映像更新为版本2,请使用set image 命令,然后是deployment 名称和 新镜像 版本:

1
2
$ kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
deployment.extensions/kubernetes-bootcamp image updated

该命令通知deployments为您的应用程序使用不同的映像,并启动滚动更新。并使用GET Pods命令查看新Pods的状态,之前的pods已经不存在:

1
2
3
4
5
6
$ kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-5bf4d5689b-2xcfb   1/1     Running   0          2m2s
kubernetes-bootcamp-5bf4d5689b-mrbb6   1/1     Running   0          2m4s
kubernetes-bootcamp-5bf4d5689b-rjpl6   1/1     Running   0          2m3s
kubernetes-bootcamp-5bf4d5689b-rq62d   1/1     Running   0          2m4s

  

步骤2:验证更新

首先,让我们检查应用程序是否正在运行。为了找出公开的IP和端口,我们可以使用describe service:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ kubectl describe services/kubernetes-bootcamp
Name:                     kubernetes-bootcamp
Namespace:                default
Labels:                   run=kubernetes-bootcamp
Annotations:              <none>
Selector:                 run=kubernetes-bootcamp
Type:                     NodePort
IP:                       10.111.214.229
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  32217/TCP
Endpoints:                172.18.0.10:8080,172.18.0.11:8080,172.18.0.8:8080 + 1 more...
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

创建一个名为Node_Port的环境变量,该变量的节点端口值为:

1
2
3
$ export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')
$ echo NODE_PORT=$NODE_PORT
NODE_PORT=32217

接下来,我们将对公开的IP和端口进行curl:

1
2
$ curl $(minikube ip):$NODE_PORT
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-5bf4d5689b-mrbb6 | v=2

我们使用每个请求访问不同的Pod,我们看到所有的Pods都在运行最新版本(V2)。

 

还可以通过运行滚出状态命令来确认更新:

1
2
$ kubectl rollout status deployments/kubernetes-bootcamp
deployment "kubernetes-bootcamp" successfully rolled out

  

若要查看该应用程序的当前图像版本,请对Pods运行描述命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
$ kubectl describe pods
Name:               kubernetes-bootcamp-5bf4d5689b-2xcfb
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:18:44 +0000
Labels:             pod-template-hash=5bf4d5689b
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.11
Controlled By:      ReplicaSet/kubernetes-bootcamp-5bf4d5689b
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://7adbc5afbaa8d7763f17529f0b54731c003b7c114e2b0e6936a17b9b6406993a
    Image:          jocatalin/kubernetes-bootcamp:v2
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:fb1a3ced00cecfc1f83f18ab5cd14199e30adc1b49aa4244f5d65ad3f5feb2a5
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:18:45 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  10m   default-scheduler  Successfully assigned default/kubernetes-bootcamp-5bf4d5689b-2xcfb to minikube
  Normal  Pulled     10m   kubelet, minikube  Container image "jocatalin/kubernetes-bootcamp:v2" already present on machine
  Normal  Created    10m   kubelet, minikube  Created container
  Normal  Started    10m   kubelet, minikube  Started container
 
 
Name:               kubernetes-bootcamp-5bf4d5689b-mrbb6
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:18:42 +0000
Labels:             pod-template-hash=5bf4d5689b
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.9
Controlled By:      ReplicaSet/kubernetes-bootcamp-5bf4d5689b
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://49a606c599140f370953d2c5ecdfd56fe2149497635eaf650977376727fd1334
    Image:          jocatalin/kubernetes-bootcamp:v2
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:fb1a3ced00cecfc1f83f18ab5cd14199e30adc1b49aa4244f5d65ad3f5feb2a5
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:18:43 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  10m   default-scheduler  Successfully assigned default/kubernetes-bootcamp-5bf4d5689b-mrbb6 to minikube
  Normal  Pulled     10m   kubelet, minikube  Container image "jocatalin/kubernetes-bootcamp:v2" already present on machine
  Normal  Created    10m   kubelet, minikube  Created container
  Normal  Started    10m   kubelet, minikube  Started container
 
 
Name:               kubernetes-bootcamp-5bf4d5689b-rjpl6
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:18:43 +0000
Labels:             pod-template-hash=5bf4d5689b
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.10
Controlled By:      ReplicaSet/kubernetes-bootcamp-5bf4d5689b
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://147bc6dec7d9e8036e4d23c0eaad891216d1c67921052c7c3ee30263c0116c55
    Image:          jocatalin/kubernetes-bootcamp:v2
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:fb1a3ced00cecfc1f83f18ab5cd14199e30adc1b49aa4244f5d65ad3f5feb2a5
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:18:43 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  10m   default-scheduler  Successfully assigned default/kubernetes-bootcamp-5bf4d5689b-rjpl6 to minikube
  Normal  Pulled     10m   kubelet, minikube  Container image "jocatalin/kubernetes-bootcamp:v2" already present on machine
  Normal  Created    10m   kubelet, minikube  Created container
  Normal  Started    10m   kubelet, minikube  Started container
 
 
Name:               kubernetes-bootcamp-5bf4d5689b-rq62d
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:18:42 +0000
Labels:             pod-template-hash=5bf4d5689b
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.8
Controlled By:      ReplicaSet/kubernetes-bootcamp-5bf4d5689b
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://ba622412c3b9350df9212c3b677d1560e1b7e37cb909c262ce73153e7ff99b2c
    Image:          jocatalin/kubernetes-bootcamp:v2
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:fb1a3ced00cecfc1f83f18ab5cd14199e30adc1b49aa4244f5d65ad3f5feb2a5
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:18:43 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  10m   default-scheduler  Successfully assigned default/kubernetes-bootcamp-5bf4d5689b-rq62d to minikube
  Normal  Pulled     10m   kubelet, minikube  Container image "jocatalin/kubernetes-bootcamp:v2" already present on machine
  Normal  Created    10m   kubelet, minikube  Created container
  Normal  Started    10m   kubelet, minikube  Started container

 

步骤3:回滚更新

查看deployments的状态:

1
2
3
$ kubectl get deployments
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   3/4     2            3           23m

出了点问题…我们没有所需数量(available状态)的pods。再次列出Pods:

1
2
3
4
5
6
7
$ kubectl get pods
NAME                                   READY   STATUS             RESTARTS   AGE
kubernetes-bootcamp-597cfc5b76-bc46g   0/1     ImagePullBackOff   0          8m25s  #状态:镜像拉回,让我们把镜像还原回原来的版本。
kubernetes-bootcamp-597cfc5b76-gh76q   0/1     ImagePullBackOff   0          8m25s
kubernetes-bootcamp-5bf4d5689b-mrbb6   1/1     Running            0          21m
kubernetes-bootcamp-5bf4d5689b-rjpl6   1/1     Running            0          21m
kubernetes-bootcamp-5bf4d5689b-rq62d   1/1     Running            0          21m

存储库中没有名为V10的映像。让我们回到我们以前的工作版本。我们将使用rollout命令

1
2
$ kubectl rollout undo deployments/kubernetes-bootcamp
deployment.extensions/kubernetes-bootcamp rolled back

ROLLOUT命令将部署恢复到以前的已知状态(映像的v2版本)。更新是版本化的,您可以恢复到任何以前知道的部署状态。再次列出Pods:

1
2
3
4
5
6
$ kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-5bf4d5689b-j54m4   1/1     Running   0          3m10s
kubernetes-bootcamp-5bf4d5689b-mrbb6   1/1     Running   0          27m
kubernetes-bootcamp-5bf4d5689b-rjpl6   1/1     Running   0          27m
kubernetes-bootcamp-5bf4d5689b-rq62d   1/1     Running   0          27m

四个pods在运行。再次检查它们的映像:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
$ kubectl describe pods
Name:               kubernetes-bootcamp-5bf4d5689b-j54m4
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:43:21 +0000
Labels:             pod-template-hash=5bf4d5689b
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.6
Controlled By:      ReplicaSet/kubernetes-bootcamp-5bf4d5689b
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://8a6566c1233f5333585c7ca905509b754f7ac93e8b7eed4a2c0a699159486606
    Image:          jocatalin/kubernetes-bootcamp:v2
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:fb1a3ced00cecfc1f83f18ab5cd14199e30adc1b49aa4244f5d65ad3f5feb2a5
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:43:22 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  3m16s  default-scheduler  Successfully assigned default/kubernetes-bootcamp-5bf4d5689b-j54m4 to minikube
  Normal  Pulled     3m15s  kubelet, minikube  Container image "jocatalin/kubernetes-bootcamp:v2" already present on machine
  Normal  Created    3m15s  kubelet, minikube  Created container
  Normal  Started    3m15s  kubelet, minikube  Started container
 
 
Name:               kubernetes-bootcamp-5bf4d5689b-mrbb6
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:18:42 +0000
Labels:             pod-template-hash=5bf4d5689b
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.9
Controlled By:      ReplicaSet/kubernetes-bootcamp-5bf4d5689b
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://49a606c599140f370953d2c5ecdfd56fe2149497635eaf650977376727fd1334
    Image:          jocatalin/kubernetes-bootcamp:v2
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:fb1a3ced00cecfc1f83f18ab5cd14199e30adc1b49aa4244f5d65ad3f5feb2a5
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:18:43 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  27m   default-scheduler  Successfully assigned default/kubernetes-bootcamp-5bf4d5689b-mrbb6 to minikube
  Normal  Pulled     27m   kubelet, minikube  Container image "jocatalin/kubernetes-bootcamp:v2" already present on machine
  Normal  Created    27m   kubelet, minikube  Created container
  Normal  Started    27m   kubelet, minikube  Started container
 
 
Name:               kubernetes-bootcamp-5bf4d5689b-rjpl6
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:18:43 +0000
Labels:             pod-template-hash=5bf4d5689b
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.10
Controlled By:      ReplicaSet/kubernetes-bootcamp-5bf4d5689b
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://147bc6dec7d9e8036e4d23c0eaad891216d1c67921052c7c3ee30263c0116c55
    Image:          jocatalin/kubernetes-bootcamp:v2
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:fb1a3ced00cecfc1f83f18ab5cd14199e30adc1b49aa4244f5d65ad3f5feb2a5
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:18:43 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  27m   default-scheduler  Successfully assigned default/kubernetes-bootcamp-5bf4d5689b-rjpl6 to minikube
  Normal  Pulled     27m   kubelet, minikube  Container image "jocatalin/kubernetes-bootcamp:v2" already present on machine
  Normal  Created    27m   kubelet, minikube  Created container
  Normal  Started    27m   kubelet, minikube  Started container
 
 
Name:               kubernetes-bootcamp-5bf4d5689b-rq62d
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/172.17.0.54
Start Time:         Tue, 09 Apr 2019 07:18:42 +0000
Labels:             pod-template-hash=5bf4d5689b
                    run=kubernetes-bootcamp
Annotations:        <none>
Status:             Running
IP:                 172.18.0.8
Controlled By:      ReplicaSet/kubernetes-bootcamp-5bf4d5689b
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://ba622412c3b9350df9212c3b677d1560e1b7e37cb909c262ce73153e7ff99b2c
    Image:          jocatalin/kubernetes-bootcamp:v2
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:fb1a3ced00cecfc1f83f18ab5cd14199e30adc1b49aa4244f5d65ad3f5feb2a5
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 09 Apr 2019 07:18:43 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6z8g2 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6z8g2:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6z8g2
    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:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  27m   default-scheduler  Successfully assigned default/kubernetes-bootcamp-5bf4d5689b-rq62d to minikube
  Normal  Pulled     27m   kubelet, minikube  Container image "jocatalin/kubernetes-bootcamp:v2" already present on machine
  Normal  Created    27m   kubelet, minikube  Created container
  Normal  Started    27m   kubelet, minikube  Started container

我们看到部署使用的是应用程序的稳定版本(V2)。回滚是成功的。

 

posted @   linuxws  阅读(1142)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示