1
votes

After building a docker image named my-http I can create a deployment from it with

kubectl create deploy http-deployment --image=my-http

This will not pull the image because imagePullPolicy is Always.

So then run

kubectl edit deploy http-deployment

and change the imagePullPolicy to Never, then it runs.

But for automation purposes I've created a yaml to create the deployment and set the imagePullPolicy at the same time.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: http-deployment
spec:
    replicas: 3
    selector:
      matchLabels:
        app: http
    template:
      metadata:
        labels:
          app: http
      spec:
        containers:
        - name: my-http
          image: my-http
          imagePullPolicy: Never
          ports:
          - containerPort: 8080

Then apply -f and the pods start running but after a while a Crashloopbackoff starts with the message

container image my-http already present on machine

Apparently it has something to do with the container port but what to use for that port to get it running? There is no container running...

edit: the image already present is just informational, this is the last line in the pod description

Warning BackOff 7s (x8 over 91s) kubelet, minikube Back-off restarting failed container

2
does that container runs using docker run? What does kubectl logs podname say ? - Arghya Sadhu
that says nothing :) - Serve Laurijssen

2 Answers

3
votes

If you using kubernetes cluster your images only available on the nodes that you build the images.

You have to push images to container registries then the kubernetes will try to pull the image to node that will running the container.

If you want to run the container in the nodes that you build the images you have to use NodeSelector, or PodAffinity.

https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/

1
votes

Your image is probably private image which Kubernetes can't pull if you didn't specify imagePullSecrets.

This shouldn't be the problem however, because imagePullPolicy: Never would just use the image on the nodes. You can diagnose real problem by either kubectl describe pod pod_name or getting logs of the previous pod with --previous flag because newer pod may not have encountered the problem.