Do you develop or plan to develop a Kubernetes native application in Golang, controller or operator? Such application strongly depends on being inside Kubernetes and development outside of Kubernetes may be a real hassle. Usually you have to build an image over and over again and restart the pod (with imagePullPolicy set to Always). This is very boring and time consuming procedure.
Two years ago I developed an image to auto-recompile and auto-restart Go application, named go-reflex , but it was intented to be used by docker-compose. Today I gave it a try with Kubernetes, namely with kind (Kubernetes in Docker) and it turned out it works like a charm. In this article I will describe how to set this up and save your time for something creative (i.e. beer drinking).
As a first step, install kind and create local cluster:
Now create a kind config file config.yaml:
Modify hostPath to match your project root directory and create the cluster:
Follow the instructions how to configure kubectl. Now deploy your pod to the cluster using the following manifest (deploy.yaml):
Replace your-app-name with the name you want. Finally create this object within the kind cluster:
Connect to your application using standard kubectl port forwarding:
Replace the second port number with correct port number where your application listens on and access it in browser or some REST client on port 3000 on your localhost.
Try to modify some .go file in your application repository and notice that your application is going to be automatically recompiled and restarted inside the cluster. You can track this by following the logs: