Does kubernetes pod restart on failure on ImgPullBackOff

7/14/2018

I have a kubernetes cluster working perfectly fine. I have 10 worker nodes and 1 master device. I have a below deployment.yaml file type as DaemonSet for pods and containers.

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: deployment    
  namespace: mynamespace   

spec:
  replicas: 2
  selector:
    matchLabels:
      name: deployment
  template:
    metadata:
      labels:
        name: deployment

    spec:
      #List of all the containers
      containers:
      - name: container1
        image: CRname/container1
        imagePullPolicy: Always
        volumeMounts:
        - mountPath: /share
          name: share-files
        securityContext:
          privileged: true

      - name: container2
        image: CRname/container2
        imagePullPolicy: Always
        volumeMounts:
        - mountPath: /share
          name: share-files
        securityContext:  
          privileged: true

      volumes:
      - name: share-files
        hostPath:
          path: /home/user/shared-folder

      imagePullSecrets:
      - name: Mysecret

      nodeSelector:
         NodeType: ALL

On starting above, these two containers start running on all the worker nodes and runs perfectly fine. But I have observed that sometimes, few nodes show error as ImagePullBackOff which means that due to some network or any other issues, it wasn't able to download the image. I did use describe command to check which image failed. But the problem is it didn't try to automatically redownload the image. I had to delete the pod and thus it is automatically created and then it works fine.

I just want to know why the pod shows this error and do not try to redownload the image. Is there anything which I can add in the yaml file so that it delete and recreate the pod automatically on any type of error.

EDIT I would also like to ask when the deployment is created, node starts to pull the image from the container registry initially for the first time. Once they are downloaded locally on the nodes, why does it has to pull the image again when the image is locally present.?

Please suggest some good options. Thanks.

-- S Andrew
kubernetes

1 Answer

7/14/2018

imagePullPolicy: Always cause you download the image everytime pod restart.

And the pod is always restarted by daemonset, so just wait a bit more time.

-- Kun Li
Source: StackOverflow