skip to Main Content

I have created a process_file.py file with content:

def fun():
    print('My name is sumit lohan')

fun()

A dockerfile with content:

FROM python:3.9
COPY process_file.py /code/

A my-deployment.yaml with content:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-container
        image: localhost:5000/my-image:latest
        command: ["python", "process_file.py"]

I build docker image using:

docker build -t my-image .

Ran registry container and mapped to port 5000 using:

docker run -d -p 5000:5000 --name registry registry:2

Created a tag using:

docker tag my-image localhost:5000/my-image

and pushed image:

docker push localhost:5000/my-image

and called kubectl apply -f my-deployment.yaml
but getting error that: container "my-pod1" in pod "my-pod1" is waiting to start: trying and failing to pull image

in my docker ps output: i had 2 containers named registry and minikube
i created network and added both conatiners in that network and used registry ip address in image at place of localhost but that also didn’t worked

Can somebody help me find the issue and what shall i use to pull image correctly?

3

Answers


  1. To do what you say, I think it isn’t necessary to push the Docker image into a Registry running on a Node where the Pod that will use it will also run.

    Check out this procedure:
    How to use local docker images with Minikube?

    If you want to create a tool-chain entirely on Kubernetes, you should create a Deployment that uses a Docker image of one of the most famous existing Docker Registries, configure it and then push your custom images in there.

    After that all your Deployments will point to the local svc (infra-cluster DNS).

    Obviously this architecture holds up as long as we talk about Dev environments; because otherwise you would need Ingress, certificates, .dockerconfigjson (assuming the infrastructure below is Production ready).

    Login or Signup to reply.
  2. You need to create a ‘secret’ with your existing credentials for your local docker where the image resides. Make sure you create the secret in the same namespace or default namespace depending on where you plan on running your pods.

    Follow these steps and check if it works:

    https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

    Login or Signup to reply.
    1. You can use the minikube image load command to load the image
      which is built on a local machine.

      Example in your case

    $ minikube image load localhost:5000/my-image

    Note: If a pod is deployed before loading the image you can restart the pod after loading the image into minikube, so that it will pull the image properly.

    1. The other way is you can build the image inside minikube using the
      following command. In this way the image is not required to load.

    $ minikube image build -t localhost:5000/my-image

    For more detailed information refer to the minikube image page

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search