当我使用AWS EC2部署k8s群集时,在其上部署一个测试容器:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: app-deployment-test
spec:
replicas: 2
template:
metadata:
labels:
app: app-test
tier: frontend
spec:
containers:
- name: app
image: ubuntu
ports:
- containerPort: 80
imagePullPolicy: Always
得到了
Back-off restarting failed container
Error syncing pod
pod上的错误。描述特殊pod:kubectl describe pod app-deployment-test-ccddf7bcc-dqltq
时,在输出尾部获取这些消息:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 41s default-scheduler Successfully assigned app-deployment-test-ccddf7bcc-dqltq to app-instance
Normal SuccessfulMountVolume 41s kubelet, app-instance MountVolume.SetUp succeeded for volume "default-token-zrf98"
Normal Pulling 14s (x3 over 40s) kubelet, app-instance pulling image "ubuntu"
Normal Pulled 12s (x3 over 32s) kubelet, app-instance Successfully pulled image "ubuntu"
Normal Created 12s (x3 over 31s) kubelet, app-instance Created container
Normal Started 11s (x3 over 31s) kubelet, app-instance Started container
Warning BackOff 11s (x3 over 27s) kubelet, app-instance Back-off restarting failed container
Warning FailedSync 11s (x3 over 27s) kubelet, app-instance Error syncing pod
失败的原因是什么?
答案 0 :(得分:3)
default command到ubuntu容器是bash
。此bash
命令将运行一次并将停止容器,这是预期的行为。
如果要保持容器运行,请在下面添加命令和参数。
command: ["/bin/sh"]
args: ["-c", "while true; do echo hello; sleep 10;done"]
我建议你运行nginx容器,它会一直运行,直到你杀死容器。