我最近通过一个简单的测试项目评估了kubernetes,我能够以这样的命令来更新状态图的图像:
kubectl set image statefulset/cloud-stateful-set cloud-stateful-container=ncccloud:v716
我现在正在尝试使我们的真实系统在Kubernetes工作,即使我尝试更新映像时,Pods都不会做任何事情,即使我基本上使用了相同的命令。
它说:
statefulset.apps"云状态"图像更新
和 kubectl describe statefulset.apps/cloud-stateful-set
说:
图像:ncccloud:v716"
但是kubectl describe pod cloud-stateful-set-0
和kubectl describe pod cloud-stateful-set-1
说:
"图像:ncccloud:最新"
ncccloud:最新是一个不起作用的图像:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
cloud-stateful-set-0 0/1 CrashLoopBackOff 7 13m
cloud-stateful-set-1 0/1 CrashLoopBackOff 7 13m
mssql-deployment-6cd4ff766-pzz99 1/1 Running 1 55m
另一个奇怪的事情是,每当我尝试应用配置的状态满集而不是>不变的。
$ kubectl apply -f k8s/cloud-stateful-set.yaml
statefulset.apps "cloud-stateful-set" configured
这是我的云状态。yaml:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: cloud-stateful-set
labels:
app: cloud
group: service
spec:
replicas: 2
# podManagementPolicy: Parallel
serviceName: cloud-stateful-set
selector:
matchLabels:
app: cloud
template:
metadata:
labels:
app: cloud
group: service
spec:
containers:
- name: cloud-stateful-container
image: ncccloud:latest
imagePullPolicy: Never
ports:
- containerPort: 80
volumeMounts:
- name: cloud-stateful-storage
mountPath: /cloud-stateful-data
volumeClaimTemplates:
- metadata:
name: cloud-stateful-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Mi
这是kubectl describe pod/cloud-stateful-set-1
的完整输出:
Name: cloud-stateful-set-1
Namespace: default
Node: docker-for-desktop/192.168.65.3
Start Time: Tue, 02 Jul 2019 11:03:01 +0300
Labels: app=cloud
controller-revision-hash=cloud-stateful-set-5c9964c897
group=service
statefulset.kubernetes.io/pod-name=cloud-stateful-set-1
Annotations: <none>
Status: Running
IP: 10.1.0.20
Controlled By: StatefulSet/cloud-stateful-set
Containers:
cloud-stateful-container:
Container ID: docker://3ec26930c1a81caa39d5c5a16c4e25adf7584f90a71e0110c0b03ecb60dd9592
Image: ncccloud:latest
Image ID: docker://sha256:394427c40e964e34ca6c9db3ce1df1f8f6ce34c4ba8f3ab10e25da6e89678830
Port: 80/TCP
Host Port: 0/TCP
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 139
Started: Tue, 02 Jul 2019 11:19:03 +0300
Finished: Tue, 02 Jul 2019 11:19:03 +0300
Ready: False
Restart Count: 8
Environment: <none>
Mounts:
/cloud-stateful-data from cloud-stateful-storage (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-gzxpx (ro)
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
cloud-stateful-storage:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: cloud-stateful-storage-cloud-stateful-set-1
ReadOnly: false
default-token-gzxpx:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-gzxpx
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 19m default-scheduler Successfully assigned cloud-stateful-set-1 to docker-for-desktop
Normal SuccessfulMountVolume 19m kubelet, docker-for-desktop MountVolume.SetUp succeeded for volume "pvc-4c9e1796-9c9a-11e9-998f-00155d64fa03"
Normal SuccessfulMountVolume 19m kubelet, docker-for-desktop MountVolume.SetUp succeeded for volume "default-token-gzxpx"
Normal Pulled 17m (x5 over 19m) kubelet, docker-for-desktop Container image "ncccloud:latest" already present on machine
Normal Created 17m (x5 over 19m) kubelet, docker-for-desktop Created container
Normal Started 17m (x5 over 19m) kubelet, docker-for-desktop Started container
Warning BackOff 4m (x70 over 19m) kubelet, docker-for-desktop Back-off restarting failed container
这是kubectl describe statefulset.apps/cloud-stateful-set
的完整输出:
Name: cloud-stateful-set
Namespace: default
CreationTimestamp: Tue, 02 Jul 2019 11:02:59 +0300
Selector: app=cloud
Labels: app=cloud
group=service
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"apps/v1","kind":"StatefulSet","metadata":{"annotations":{},"labels":{"app":"cloud","group":"service"},"name":"cloud-stateful-set","names...
Replicas: 2 desired | 2 total
Pods Status: 2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: app=cloud
group=service
Containers:
cloud-stateful-container:
Image: ncccloud:v716
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts:
/cloud-stateful-data from cloud-stateful-storage (rw)
Volumes: <none>
Volume Claims:
Name: cloud-stateful-storage
StorageClass:
Labels: <none>
Annotations: <none>
Capacity: 10Mi
Access Modes: [ReadWriteOnce]
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 25m statefulset-controller create Pod cloud-stateful-set-0 in StatefulSet cloud-stateful-set successful
Normal SuccessfulCreate 25m statefulset-controller create Pod cloud-stateful-set-1 in StatefulSet cloud-stateful-set successful
如果很重要,我正在使用docker桌面。
在我的情况下,imagepullpolicy始终已经设置为:
kubectl patch statefulset web --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"gcr.io/google_containers/nginx-slim:0.8"}]'
在我的情况下,请参阅K8S文档:https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#rollling-update
在状态集yaml中,更改
imagePullPolicy: Never
to
imagePullPolicy: Always
我遇到了一个几乎相同的问题。我正在使用状态范围的单元舱。我已经始终设置了ImagePullPolicy。吊舱卡在退回循环中,不会使用新图像进行更新。
事实证明,陷入循环的图像规格是标签"最新标签"的图像。不存在;控制平面被卡在带有错误rpc error: code = NotFound desc = failed to pull and unpack image...
似乎需要删除和重新创建ImagePullbackoff状态中的POD。我相信对于crashloopbackoff状态的豆荚也是如此。
似乎也可以更新状态集的规格,而POD仍陷入了向后循环,并且不会更新。即状态满足规格和POD规格不匹配。
对我解决这种情况的是两种解决方案之一:
删除并重新创建POD(不是首选(
kubectl delete statefulset my-statefulset
kubectl apply -f my-statefulset.yml
(其中my-statefulset.yml是此POD的YAML规格(
或将吊舱缩放到零复制品,然后备份到一个(首选(
kubectl scale statefulset my-statefulset --replicas=0 &&
kubectl scale statefulset my-statefulset --replicas=1
此外,重新创建POD时可以添加spec.podManagementPolicy: Parallel
。该策略允许创建一个新的POD,而无需等待删除卡在Crashloopbackoff中的杂物。最终,这就是我解决这个问题的未来发生的方式。
另请参见:
- kubernetes中带有crashloopbackoff状态的重新发行状态
- 如何清除crashloopbackoff