Often we like to develop kubernetes applications locally and deploy it to minikube for testing purposes. The workflow involves:
- Edit code (& compile)
- Build & tag docker image
- Push the image to a local registry
- Update image tag in the deployment yaml
- Execute kubectl / helm upgrade on the local minikube cluster
To achieve this, we need to have a local docker registry running on minikube, configure docker daemon and deployments correctly. For this tutorial I am using kubernets
v1.12.6 and minikube
For the registry, let's enable the minikube registry addon:
$ minikube addons enable registry
By default, the registry has a service type of
clusterIP. Let's update this and change it to
NodePort. If you want a consistent port, add a
NodePort value as well, e.x. 30237. Once the service is saved, your registry will be accessible from the host machine
http://minikube-vm-ip:30237/v2/_catalog. Get the IP address using
$ minikube ip
To use this registry from your host machine, you need to add this IP address to the insecure registries daemon configuration. For mac, go to
Docker desktop preferences -> Daemon -> Basic -> Add insecure registry.
Once this is done, you can build and push images to this registry.
$ docker build -t minikube-vm-ip:30237/my-image:1 . $ docker push minikube-vm-ip:30237/my-image:1
Now the kubernetes part. Copy the
clusterIP of the registry service running on
kube-system namespace and put it on the pod spec's image:
... spec: replicas: 1 template: spec: containers: - name: my-container image: <cluster-ip>:80/my-image:1 ...
Here port 80 is fine as it's the default configuration.