Lately I’ve been deployment all my services on Kubernetes. It’s really great.
When developing my code, I usually test everything on a local Kubernetes cluster. When working on Linux, I use microk8s and can access my pods and services directly using their IP address, because they share the same network.
On OSX, I’m using minikube and it’s not that straightforward. I struggled to get it working so here is how I managed to do it:
- Install hyperkit:
git clone https://github.com/moby/hyperkit cd hyperkit make && sudo ln -s $(pwd)/build/hyperkit /usr/local/bin/hyperkit
- Install minikube:
brew install minikube
- Launch minikube and specify a custom cidr for services:
minikube start --driver=hyperkit --service-cluster-ip-range=172.17.0.0/16
- Tell OSX to route traffic to minikube for specified cidr:
sudo route -n add 172.17.0.0/16 $(minikube ip)
- Check minikube kube-dns IP address (usually 172.17.0.10):
kubectl --namespace=kube-system get svc
- Tell OSX to use kube-dns as well for name resolution (you may need to turn your internet connection on and off to take it into account):
sudo echo "nameserver 172.17.0.10" > /etc/resolver/cluster.local
- If you have a Kubernetes service running, with name “test” in default namespace and listening on port 80, you should be able to directly access it using it’s kube-dns hostname: test.default.svc.cluster.local:80