go-minikube-vscode-dev
This repo is a template to get started writing golang applications designed to run in Kubernetes. It requires that minikube (https://github.com/kubernetes/minikube) is already installed.
How to use
- Type a bunch of go code
- Make sure that the "Remote Minikube" launch configuration is selected in vscode
- Set a breakpoint or whatever
- F5
- Unfortunately debug out isn't printing into the console. You can use
kubectl logs go-debug --tail=30 --follow
as a substitute for now.
How it works
- The "Remote Minikube" launch configuration has
deployToMinikube
setup as a prelaunch task deployToMinikube
runsdebug.sh
debug.sh
builds a container withdebug.Dockerfile
.dockerignore
ignores everything except themain
binary
debug.sh
usesdebug.podspec.yml
to install your application/service into minikube. Adjust as necessary to expose other ports. Delve uses 2345 so leave that one alone.- The last line of
debug.sh
prints out the exposed endpoints on your container. Currentlylaunch.json
is hardcoded to try to connect to the debugger at 192.168.99.100. This will need to be adjusted if the service is exposed at a different IP.
A Better Approach
See this project https://github.com/number101010/go-kubernetes-vscode-dev for a much better development experience. The only thing that this project does better is actually run your code in the cluster which gives you access to the container file system. See the caveats section in the go-kubernetes-vscode-dev
readme.md for more details.
Once I fix the issue where pods fail to terminate then this project will be a much slower but more complete solution. The other project will become a much faster lightweight solution.
Issues/Improvements
- Print application output into vscode debug console
- Occassionally the pod/container fail to terminate. (Stopping Minikube VM is the best way I've found to fix this)
- Windows support
- Use
kubectl port-forward
to expose 2345 on localhost - Add example usage of ./src directory
- Cleanup/Replace pods better