problems with the "alpine" image for my initContainers

11/20/2018

People, I am trying to create a simple file /tmp/tarte.test with initContainers. I have a constraint, using an alpine image for the container. Please let me know what is NOT in this simple yaml file.

apiVersion: v1
kind: Pod
metadata:
  name: initonpod
  namespace: prod
  labels:
    app: myapp
spec:
  containers:
  - name: mycont-nginx
    image: alpine
  initContainers:
    - name: myinit-cont
      image: alpine
      imagePullPolicy: IfNotPresent
      command: 
      - touch
      - "/tmp/tarte.test"
      - sleep 200

the describe of the pod

Events:
  Type     Reason     Age              From                 Message
  ----     ------     ----             ----                 -------
  Normal   Scheduled  9s               default-scheduler    Successfully assigned prod/initonpod to k8s-node-1
  Normal   Pulled     8s               kubelet, k8s-node-1  Container image "alpine" already present on machine
  Normal   Created    8s               kubelet, k8s-node-1  Created container
  Normal   Started    7s               kubelet, k8s-node-1  Started container
  Normal   Pulling    4s (x2 over 7s)  kubelet, k8s-node-1  pulling image "alpine"
  Normal   Pulled     1s (x2 over 6s)  kubelet, k8s-node-1  Successfully pulled image "alpine"
  Normal   Created    1s (x2 over 5s)  kubelet, k8s-node-1  Created container
  Normal   Started    1s (x2 over 5s)  kubelet, k8s-node-1  Started container
  Warning  BackOff    0s               kubelet, k8s-node-1  Back-off restarting failed container

And if I change the alpine image for an nginx image container... it's work good.

-- manzion_111
containers
kubernetes
microk8s
yaml

1 Answer

11/20/2018

Back-off restarting failed container because of your container spec.

spec:
  containers:
  - name: mycont-nginx
    image: alpine

This alpine container doesn't run forever. In kubernetes, container has to run forever.That's why you are getting error. When you use nginx image, it runs forever. So to use alpine image change the spec as below:

apiVersion: v1
kind: Pod
metadata:
  name: busypod
  labels:
    app: busypod
spec:
  containers:
  - name: busybox
    image: alpine
    command:
    - "sh"
    - "-c"
    - >
      while true; do
        sleep 3600;
      done
  initContainers:
  - name: myinit-cont
    image: alpine
    imagePullPolicy: IfNotPresent
    command:
    - touch
    - "/tmp/tarte.test"
    - sleep 200
-- nightfury1204
Source: StackOverflow