How can I make host docker images available to k8s Deployment?



  • I have a k8s pod that is running docker. My issue is that for the docker images on my host machine to be available within the pod I either have to run the image as a pod or run a docker pull script at the beginning of my deployment.

    Docker's pull API rate limits after some time and these images are not meant to be run without inputs, so I would like to know if there's another way to either expose the host's docker or get access to those images.

    I am currently trying to expose the local docker socket, but that does not appear to be provide access to the Deployment from the local docker instance. I'm testing by running docker images inside the Deployment and on the host to see if the images match which they don't.

    volumeMounts:
        - mountPath: /var/run/docker.sock:ro
          name: docker-sock
    ...
    volumes:
        - name: docker-sock
        hostPath:
            path: /var/run/docker.sock
    

    I'm also mounting with minikube like so

    minikube start --memory='5000MB' --mount --mount-string='/:/k8s' --cpus='4'
    


  • As the https://github.com/kubernetes/minikube/blob/0c616a6b42b28a1aab8397f5a9061f8ebbd9f3d9/README.md#reusing-the-docker-daemon describes, you can reuse the Docker daemon from Minikube with eval $(minikube docker-env).

    So to use an image without uploading it, you can follow these steps:

    1. Set the environment variables with eval $(minikube docker-env)
    2. Build the image with the Docker daemon of Minikube (eg docker build -t my-image .)
    3. Set the image in the pod spec like the build tag (eg my-image)
    4. Set the https://kubernetes.io/docs/concepts/containers/images/#updating-images to Never, otherwise Kubernetes will try to download the image.

    Important note: You have to run eval $(minikube docker-env) on each terminal you want to use, since it only sets the environment variables for the current shell session.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2