I am creating a Replication controller with one init-container. however the init container fails to start and the status of the pod is:
NAME READY STATUS RESTARTS AGE
testcontainer 0/1 CrashLoopBackOff 12 37m
I am not sure what part is failing exactly, and the logs do not help. My kubectl server version is 1.4 (different from client version) so I am using:
annotations:
pod.beta.kubernetes.io/init-containers:
Here is the replication controller yaml file I am using. I am using the "hello-world" image (instead of the nginx to make it faster)
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
logs from 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
when I check the logs of both containers (nginx and testcontainer) it shows the output of running the hello-world image, so I guess the image is downloaded and started successfully. Im not sure what fails after that ( I even tried creating a single pod, using the example provided on https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-initialization/#creating-a-pod-that-has-an-init-container , but still fails)
I think the problem here isn't the init container. The hello-world
image print a text and exits immediately. Since .spec.restartPolicy
of the pod defaults to Always
, it just restarts the pod every time.
The error message might be a bit confusing, but since the pod is intended to run forever it quite makes sense to display an error, even if the exit code is 0
.
If you want to run a pod only a single time, you should use the job API.
Since you are interested in an example for the init-container, I fixed your example:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With