0

Net core application image and I am trying to create deployment in local kubernetes. I created docker image as below.

docker tag microservicestest:dev microservicestest .
docker build -t microservicestest .
docker run -d -p 8080:80 --name myapp microservicetest

Then I created deployment as below.

kubectl run microservicestest-deployment --image=microservicestest:latest --port 80 --replicas=3
kubectl expose deployment microservicestest-deployment --type=NodePort

then when I see Kubectl get pods I see below error

enter image description here

Below is the output when I run docker images

enter image description here

Below is the output

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2020-09-22T04:29:14Z"
  generation: 1
  labels:
    run: microservicestest-deployment
  name: microservicestest-deployment
  namespace: default
  resourceVersion: "17282"
  selfLink: /apis/apps/v1/namespaces/default/deployments/microservicestest-deployment
  uid: bf75410a-d332-4016-9757-50d534114599
spec:
  progressDeadlineSeconds: 600
  replicas: 3
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      run: microservicestest-deployment
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: microservicestest-deployment
    spec:
      containers:
      - image: microservicestest:latest
        imagePullPolicy: Always
        name: microservicestest-deployment
        ports:
        - containerPort: 80
          protocol: TCP
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  conditions:
  - lastTransitionTime: "2020-09-22T04:29:14Z"
    lastUpdateTime: "2020-09-22T04:29:14Z"
    message: Deployment does not have minimum availability.
    reason: MinimumReplicasUnavailable
    status: "False"
    type: Available
  - lastTransitionTime: "2020-09-22T04:29:14Z"
    lastUpdateTime: "2020-09-22T04:29:14Z"
    message: ReplicaSet "microservicestest-deployment-5c67d587b9" is progressing.
    reason: ReplicaSetUpdated
    status: "True"
    type: Progressing
  observedGeneration: 1
  replicas: 3
  unavailableReplicas: 3
  updatedReplicas: 3

I am not able to understand why my pods are not able to pull the image from local. Can someone help me to identify the issue What I am making here. Any help would be appreciated. Thank you

Mr Perfect
  • 585
  • 8
  • 30

2 Answers2

6

if you are using minikube you first need to build the images in the docker hosted in the minikube machine doing this in your bash session eval $(minikube docker-env) for windows check here

then you need to tell Kubernetes your image pull policy to be Never or IfNotPresent to look for local images

spec:
     containers:
     - image: my-image:my-tag
       name: my-app
       imagePullPolicy: Never

check here the official documentation

By default, the kubelet tries to pull each image from the specified registry. However, if the imagePullPolicy property of the container is set to IfNotPresent or Never, then a local image is used (preferentially or exclusively, respectively).

as you are not using yaml file you can create the resources like this

kubectl run microservicestest-deployment --image=microservicestest:latest --image-pull-policy=Never --port 80 --replicas=3

kubectl expose deployment microservicestest-deployment --type=NodePort

cperez08
  • 709
  • 4
  • 9
  • Hi Thanks for your answer. I have installed docker in my local system. Also how to set eval $(minikube docker-env)? Where can Iset above spec? – Mr Perfect Sep 22 '20 at 04:26
  • something like this should work `kubectl run microservicestest-deployment --image=microservicestest:latest --image-pull-policy=Never --port 80 --replicas=3` I just updated the answer – cperez08 Sep 22 '20 at 04:29
  • about the eval thing check this answer https://stackoverflow.com/questions/48376928/on-windows-setup-how-can-i-get-docker-image-from-local-machine – cperez08 Sep 22 '20 at 04:33
  • Above code worked for me. But what is the root cause? – Mr Perfect Sep 22 '20 at 04:36
  • Kubernetes by default goes to the specified registry (most of the cases in the docker registry) in order to pull the images, that's why when using local set up a different pull policy needs to be specified. https://kubernetes.io/docs/concepts/containers/images/#pre-pulled-images – cperez08 Sep 22 '20 at 04:38
  • Now I deployed azure kubernetes and there also i started getting same error ImagePullBackOff. Here I have yml file. I have policy set imagePullPolicy: Always restartPolicy: Always – Mr Perfect Sep 22 '20 at 04:59
  • I think that's a different issue, it is ok to use Always as policy in the cloud but have you published you docker image? or are you still trying to use a kind of local/custom image? – cperez08 Sep 22 '20 at 05:47
0

I found an interesting work around for this issue. For me this turned out to be something missing in my original deployment.yml file

  1. Deploy the container from the CLI

oc create deployment arcade --image=
default-route-openshift-image-registry.apps-crc.testing/arcade/game

  1. Go to the the openshift console and copy paste the deployment.yml

  2. Delete the deployment

oc delete deployment arcade

  1. Run the deployment with the deployment.yml you pulled from the GUI

oc apply -f deployment.yml

  • Hi, please read [formatting help](https://stackoverflow.com/help/formatting). Thank you – pierpy Aug 08 '23 at 05:30
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34791279) – Nataraj Medayhal Aug 10 '23 at 06:58