我正在创建一个具有一个 init container 的 Replication controller。然而,init container 无法启动,pod 的状态为:
NAME READY STATUS RESTARTS AGE
testcontainer 0/1 CrashLoopBackOff 12 37m
我不确定到底哪个部分出了问题,而且日志也没有帮助。我的 kubectl 服务器版本是 1.4(与客户端版本不同),因此我正在使用:
annotations:
pod.beta.kubernetes.io/init-containers:
这里是我正在使用的复制控制器 yaml 文件。 我正在使用“hello-world”映像(而不是 nginx),以使其更快。
apiVersion: v1
kind: ReplicationController
metadata:
name: testcontainer
spec:
replicas: 1
selector:
app: nginx
template:
metadata:
labels:
app: nginx
annotations:
pod.beta.kubernetes.io/init-containers: '[
{
"name": "install",
"image": "hello-world"
}
]'
spec:
containers:
- name: nginx
image: hello-world
dnsPolicy: Default
nodeName: x.x.x.x
kubectl describe pod的日志:
Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "nginx" with CrashLoopBackOff: "Back-off 5m0s restarting failed container=nginx pod=testcontainer()"
32m 16s 145 {kubelet x.x.x.x} spec.containers{nginx} Warning BackOff Back-off restarting failed docker container
当我检查nginx和testcontainer的日志时,显示运行hello-world镜像的输出,因此我想这个镜像已经成功下载并启动了。但我不确定之后出了什么问题(我甚至尝试创建一个单独的pod,使用在https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-initialization/#creating-a-pod-that-has-an-init-container上提供的示例,但仍然失败了)。
nginx
的容器开始运行。该容器也使用了 hello-world 镜像。您应该替换此镜像。 - svenwltrkubectl exec POD -c NAME
不起作用,我猜它还没有被实现。 - svenwltr