This guide will show you how to access services within your minikube instance.
First, we will need to add a route to minikube.
This oneliner gets the ClusterIP range from etcd and adds a route.
sudo route -n add -net $(minikube ssh -- sudo docker run -i --rm --net=host quay.io/coreos/etcd:v3.2 etcdctl get /registry/ranges/serviceips | jq -r '.range') $(minikube ip)
To test, deploy nginx.
kubectl run nginx --image=nginx --replicas=1
kubectl expose deployment nginx --port=80 --target-port=80 --type=LoadBalancer
And connect to it:
nginx_ip=$(kubectl get svc nginx -o jsonpath='{.spec.clusterIP}')
curl $nginx_ip
Minikube does not provision an external IP when type=LoadBalancer. This prevents some apps that talk to the k8s API from working properly.
A custom controller must be run on your Minikube cluster to enable this functionality.
DO NOT RUN THIS ON A NON-MINIKUBE CLUSTER!!
kubectl run minikube-lb-patch --replicas=1 --image=elsonrodriguez/minikube-lb-patch:0.1 --namespace=kube-system
This controller will assign the External IP to the ClusterIP, which has been made routable in the previous section.
kubectl get svc
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.0.0.1 <none> 443/TCP 18d
nginx 10.0.0.98 10.0.0.98 80:31834/TCP 40s
Nothing should change connectivity-wise, however your app can now just scrape the usual field for external ip:
nginx_external_ip=$(kubectl get svc nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
curl $nginx_external_ip
To undo all this:
kubectl delete deployment nginx
kubectl delete svc nginx
kubectl delete deployment minikube-lb-patch -nkube-system
sudo route -n delete -net $(minikube ssh -- sudo docker run -i --rm --net=host quay.io/coreos/etcd:v3.2 etcdctl get /registry/ranges/serviceips | jq -r '.range') $(minikube ip)
etcdctl get /registry/ranges/serviceips returns nothing, there is no such /registry directory in the minikube etcd