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
Once you start the minikube cluster and reuse the Docker daemon, you need to pull the Docker image:
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:It creates the
http-echo
pod from the docker image, and you can ensure that by thekubectl 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: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.(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 removeimage-pull-policy
option from your CLI.https://kubernetes.io/docs/concepts/containers/images/#updating-images
see Notes.
Instead, specify a meaningful tag such as v1.42.0 and/or a digest.
port-forward is naive way to access pod.
https://kubernetes.io/docs/concepts/services-networking/service/