Minikube + Cloud Code + VSCode
Minikube + Cloud Code + VSCode
Using Google Cloud Code for cloud-native app development? Love coding on VSCode? Here's how to use minikube to get Kubernetes integrated with them.
Join the DZone community and get the full member experience.Join For Free
You can then make real time changes to your code and the app will deploy in the background automatically.
- Install kubectl – https://kubernetes.io/docs/tasks/tools/install-kubectl/
- Install minikube – https://kubernetes.io/docs/tasks/tools/install-minikube/
- For Windows users, I recommend the Chocolaty approach
- Configure Google Cloud Code to use minikube.
- Deploy your application to your local minikube cluster in Visual Studio Code
- Ensure you add your container registry in the .vscode\launch.json file – See Appendix
Also, ensure you are running Visual Studio Code as an Administrator.
Once deployed, you can make changes to your code, and it will automatically be deployed to the cluster.
Not quite what you're looking for? Then check out our collection of our best Kubernetes articles.
Create a minikube Cluster in Windows (Hyper-V) and Deploy a Simple Web Server
Grab the output from the minikube
hello-minikube –url and browse your web app/service.
Starting the minikube Cluster and Deploying a Default Container
VS Code Deployment
- Setup your Container Registry in the
- Click Cloud Code on the bottom tray
- Click "Run on Kubernetes "
- Open a separate command prompt as administrator
We can see our new service is being deployed by VSCode Cloud Code extension. Whenever we make changes to the code, it will automatically deploy.
The above command will give us the URL to browse the web app.
If I now change the text for "Hello, world!" it will automatically deploy. Just refresh the browser.
Here in the status bar, we can see deployments as we update code.
Once you have deployed your app to minikube, you can then kick off debugging. This is pretty awesome. Basically, your development environment is now a full Kubernetes stack with attached debugging proving a seamless experience.
Check out https://cloud.google.com/code/docs/vscode/debug#nodejs for more information.
You will notice that in the launch.json file, we set up the debugger port, etc. Below, I am using port 9229. So all I need to do is start the app with:
Or, in the launch.json file, I can set set
"args": ["-inspect=9229"]. This is only supported in launch request type.
Also, ensure the Pod Selector is correct. You can use the pod name or label. You can confirm the pod name using the minikube dashboard.http://127.0.0.1:61668/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/pod?namespace=default
Now we can do the following
- Click Run on Kubernetes
- Set a Break Point
- Click Debug on Kubernetes
- Run the command prompt, PowerShell and VSCode as Administrator
- Use Choco for Windows installs
- If you are going to reboot/sleep/shut down your machine. Please run:
If you do not, you risk corrupting Hyper-V and you will get all sorts of issues.
Published at DZone with permission of Romiko Derbynew , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.