我正在使用一个init容器创建一个Replication控制器。但是,初始化容器无法启动,并且容器的状态为:
NAME READY STATUS RESTARTS AGE
testcontainer 0/1 CrashLoopBackOff 12 37m
Run Code Online (Sandbox Code Playgroud)
我不确定哪一部分完全失败了,日志也无济于事。我的kubectl服务器版本为1.4(与客户端版本不同),因此我正在使用:
annotations:
pod.beta.kubernetes.io/init-containers:
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的复制控制器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
Run Code Online (Sandbox Code Playgroud)
来自kubectl的日志描述了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
Run Code Online (Sandbox Code Playgroud)
当我检查两个容器(nginx和testcontainer)的日志时,它显示了运行hello-world映像的输出,因此我猜想该映像已下载并成功启动。我不确定之后会发生什么(我什至尝试使用https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-initialization/#creating-a-有一个初始化容器的pod,但仍然失败)
我认为这里的问题不是 init 容器。图像hello-world打印文本并立即退出。由于.spec.restartPolicypod 默认为Always,因此每次都会重新启动 pod。
错误消息可能有点令人困惑,但由于 Pod 旨在永远运行,所以显示错误是很有意义的,即使退出代码是0。
如果您只想运行一个 pod 一次,您应该使用job API。
由于您对 init-container 的示例感兴趣,因此我修复了您的示例:
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: nginx # <--- this image shouldn't be a single shot application
dnsPolicy: Default
nodeName: x.x.x.x
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6542 次 |
| 最近记录: |