skip to Main Content

I have installed the kubectl command line tool with the v1.27.2 client version, v5.0.1 kustomize version, and v1.26.3 server version. I am using minikube v1.30.1 on Microsoft Windows 10 Enterprise and Git Bash. I started the minikube cluster by:

minikube start

Then, I reused the Docker daemon inside minikube cluster:

eval $(minikube docker-env)

Now, I would like to test the hashicorp/http-echo docker image inside the minikube cluster. I tried to run the image as a docker container:

docker run -p 5678:5678 hashicorp/http-echo -text="hello world"

However, if I visit the http://localhost:5678/ site in my browser, it is not reachable. So I deleted the docker image forcefully and exited the docker environment from minikube:

docker rmi -f docker.io/hashicorp/http-echo:latest
eval $(minikube docker-env -u)

If I rerun the docker image without minikube, everything is working as expected. But how can I test the docker image that is inside the minikube cluster in my browser?

2

Answers


  1. Chosen as BEST ANSWER

    Once you start the minikube cluster and reuse the Docker daemon, you need to pull the Docker image:

    docker pull hashicorp/http-echo
    

    Make sure that the image is present by executing the minikube image ls command. After that, use the Kubernetes command line tool run command instead of Docker:

    kubectl run http-echo --image=hashicorp/http-echo:latest --image-pull-policy=Never
    

    It creates the http-echo pod from the docker image, and you can ensure that by the kubectl get pod command. Moreover, it disables the image pull policy since the docker image is already in the local minikube cluster. The last step is to expose the pod's port to reach it in the browser:

    kubectl port-forward http-echo 8080:5678
    

    The pod's port is 5678 and the local port will be 8080. Now, you should be able to access the service in your browser at http://localhost:8080 site.

    To delete the pod, execute the kubectl delete pod http-echo command.

    Note: You can reduce the number of steps by omitting the image pull policy parameter which allows you to download the image from Docker Hub. But if you build your custom image with docker build -t <my-image> . command then the --image-pull-policy=Never parameter will make sense because you don't want to pull the docker image from external sources.


    1. you should not use [:latest] tag on image, even you use (eval $(minikube docker-env)). because It internally fetch from remote repository rather than local image. you should specified tag name [:1.xx, :test etc]. then you can use remove image-pull-policy option from your CLI.

    https://kubernetes.io/docs/concepts/containers/images/#updating-images
    see Notes.

    You should avoid using the :latest tag when deploying containers in production as it is harder to track which version of the image is running and more difficult to roll back properly.

    Instead, specify a meaningful tag such as v1.42.0 and/or a digest.

    1. you can also use service rather than port-forward.
      port-forward is naive way to access pod.
      https://kubernetes.io/docs/concepts/services-networking/service/
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search