DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Mastering Cloud Containerization: A Step-by-Step Guide to Deploying Containers in the Cloud
  • Cloud Migration: Azure Blob Storage Static Website
  • Auto-Scaling a Spring Boot Native App With Nomad
  • A Comparison of Current Kubernetes Distributions

Trending

  • How to Format Articles for DZone
  • Beyond Microservices: The Emerging Post-Monolith Architecture for 2025
  • How Clojure Shapes Teams and Products
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit Using Container Images (Part 2)
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Minikube + Cloud Code + VSCode

Minikube + Cloud Code + VSCode

By 
Romiko Derbynew user avatar
Romiko Derbynew
·
Feb. 11, 20 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
9.6K Views

Join the DZone community and get the full member experience.

Join For Free

As a developer, you can deploy your Docker containers to a local Kubernetes cluster on your laptop using minikube. You can then use the Google Cloud Code extension for Visual Studio Code.

You can then make real time changes to your code and the app will deploy in the background automatically.

  1. Install kubectl – https://kubernetes.io/docs/tasks/tools/install-kubectl/
  2. Install minikube – https://kubernetes.io/docs/tasks/tools/install-minikube/
    • For Windows users, I recommend the Chocolaty approach
  3. Configure Google Cloud Code to use minikube.
  4. Deploy your application to your local minikube cluster in Visual Studio Code
  5. 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.

Create a minikube Cluster in Windows (Hyper-V) and Deploy a Simple Web Server

Shell
 




x
6


 
1
minikube start --vm-driver=hyperv
2
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.10
3
kubectl expose deployment hello-minikube --type=NodePort --port=8080
4
kubectl get pod
5
minikube service hello-minikube --url
6
minikube dashboard
62
  



Grab the output from the minikube hello-minikube –url and browse your web app/service.

Appendix

Starting the minikube Cluster and Deploying a Default Container

starting-minikube-cluster


VS Code Deployment


  • Setup your Container Registry in the .vscode\launch.json (detailed below)
  • Click Cloud Code on the bottom tray
  • Click "Run on Kubernetes "
  • Open a separate command prompt as administrator

.vscode\launch.json:

JSON
 




x
27


 
1
{
2
    "version": "0.2.0",
3
    "configurations": [
4
        {
5
            "name": "Run on Kubernetes",
6
            "type": "cloudcode.kubernetes",
7
            "request": "launch",
8
            "skaffoldConfig": "${workspaceFolder}\\skaffold.yaml",
9
            "watch": true,
10
            "cleanUp": true,
11
            "portForward": true,
12
            "imageRegistry": "romikocontainerregistry/minikube"
13
        },
14
        {
15
            "podSelector": {
16
                "app": "node-hello-world"
17
            },
18
            "type": "cloudcode",
19
            "language": "Node",
20
            "request": "attach",
21
            "debugPort": 9229,
22
            "localRoot": "${workspaceFolder}",
23
            "remoteRoot": "/hello-world",
24
            "name": "Debug on Kubernetes"
25
        }
26
    ]
27
}



debug-on-kubernetes


Shell
 




xxxxxxxxxx
1


 
1
minikube dashboard



kubernetes-service


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.

Shell
 




x
1


 
1
minikube service nodejs-hello-world-external --url



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.

kubernetes-deployments
kubernetes-demo-deployment

Debugging

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:   

Shell
 




x


 
1
CMD [“node”, “–inspect=9229”, “app.js”]




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
kubernetes-pod-selector
JSON
 




x
28


 
1
{
2
    "version": "0.2.0",
3
    "configurations": [
4
        {
5
            "name": "Run on Kubernetes",
6
            "type": "cloudcode.kubernetes",
7
            "request": "launch",
8
            "skaffoldConfig": "${workspaceFolder}\\skaffold.yaml",
9
            "watch": true,
10
            "cleanUp": true,
11
            "portForward": true,
12
            "imageRegistry": "dccausbcontainerregistry/minikube",
13
            "args": ["--inspect=9229"]
14
        },
15
        {
16
            "name": "Debug on Kubernetes",
17
            "podSelector": {
18
                "app": "nodejs-hello-world"
19
            },
20
            "type": "cloudcode",
21
            "language": "Node",
22
            "request": "attach",
23
            "debugPort": 9229,
24
            "localRoot": "${workspaceFolder}",
25
            "remoteRoot": "/hello-world"
26
        }
27
    ]
28
}



Now we can do the following


  1. Click Run on Kubernetes
  2. Set a Break Point
  3. Click Debug on Kubernetes
kubernetes-on-vscode

Tips


  • 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:
Shell
 




xxxxxxxxxx
1


 
1
minikube stop



If you do not, you risk corrupting Hyper-V and you will get all sorts of issues.

Further Reading

Microservices With Kubernetes and Docker


Visual Studio Code Kubernetes Cloud Docker (software)

Published at DZone with permission of Romiko Derbynew, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Mastering Cloud Containerization: A Step-by-Step Guide to Deploying Containers in the Cloud
  • Cloud Migration: Azure Blob Storage Static Website
  • Auto-Scaling a Spring Boot Native App With Nomad
  • A Comparison of Current Kubernetes Distributions

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!