Kubernetes Quick Start Guide

This document will provide a step-by-step tutorial on how to use our CLI for Kubernetes development. We will use the Google Microservices Demo as an example here. We will walk through the steps of creating a new template, deploying services, and intercepting services.

Prerequisites #

DevZero CLI: Follow the steps here to install the CLI

Summary #

This document is a step-by-step tutorial on how to use the DevZero CLI for Kubernetes development, using the Google Microservices Demo as an example. The tutorial covers creating a new template, deploying services, and intercepting services.

To create a template, users need to provide a container image, repositories to clone in the Devpod, and a script executed during initialization.

To create a Devpod, users need to run the dz kube new command and select the template.

The tutorial also covers intercepting a service for local development and testing. The document also provides troubleshooting tips and other helpful commands that can be used with the CLI.

Creating a Template #

A template consists of a container image, repositories that you want to clone in your Devpod, and a bash script (scriptpolicy) that is executed during initialization of the Devpod.

To create a new template run the following command in your terminal:

dz kube template new

Then, follow the prompts:

  • Add a name for your template and press enter.
  • Add a description for your template and press enter.
  • Select an image for the template. This is a docker image that includes the configuration for your devpod. You can create a new image using dz kube image new or select an existing image from the list. Press enter to continue.
  • Then you will be asked to edit the scriptpolicy. This will be run in the background during initialization of your devpod. Delete the example script and paste the script given below. Exit the editor and press enter.
sudo apt-get install gettext-base
cd /home/devzero/projects/microservices-demo && kubectl apply -f ./release/kubernetes-manifests.yaml
  • Finally, add the repos you want to clone in the devpod. For this example, copy the following repository and press enter. Your new template will now be created successfully.
- url: https://github.com/GoogleCloudPlatform/microservices-demo
  path: /home/devzero/projects

In this section we learned how to create a new template for a Devpod, which includes a container image, repositories, and a bash script that runs during initialization. To create a new template, the user needs to run the dz kube template new command in the terminal and follow the prompts to provide a name, description, and image for the template. The user then needs to edit the scriptpolicy and finally, the user should add the repositories they want to clone in the Devpod.
Run dz kube template new --help for information on the available flags.

Creating a new Devpod #

A Devpod is a Kubernetes pod that is specifically configured for development purposes and tailored to the developer's needs. It provides developers with a controlled and isolated environment for developing, testing, and debugging code in a Kubernetes cluster.

Now we will create a new Devpod using the template we created above.

Run dz kube new to create a new Devpod. Follow the prompts in the terminal:

  • Select the cluster where you want to create your devpods and press enter.
  • Select the template you want to use for your devpod. For this example we will use the template created earlier. The template script will be run in background after initialization of your devpod. Confirm template selection and press enter.

Congratulations! A new devpod will be created in the cluster you selected.

Once the Devpod creation is successful you will be logged into your machine, the script will be running in the background, and the repos you requested will be cloned.

To check the logs of the script you can run cat ~/.init.log

For this example, you can run kubectl get service frontend-external | awk '{print $4}' to get the load balancer endpoint where your application is running.

create a new devpod
Doc Image

Intercept a service #

In this section we will learn how to make changes to a microservice and deploy locally to reflect those changes.

First, open your project in your preferred Integrated Development Environment (IDE) such as Visual Studio Code (VS Code) or PyCharm. For example, if you want to open your projects in VS Code, in the terminal
run dz kube ide code. Select the same cluster you chose while creating the devpod. Then select the devpod created in the previous step, and finally select the project which you want to open in the IDE.

Once you have the Microservices Demo project open, open a terminal in the IDE and run kubectl get pods to retrieve information about all the pods running in the cluster. You will be able to see multiple microservices running.

Now, let's learn how to intercept a service locally. This can be extremely useful when you need to make changes to one of the services and test how the application would behave in production without actually deploying it. Intercepting a service allows you to run that service locally on your development pod (devpod), and all other services connected to it will point to this pod.

For this example, we will intercept the productCatalogService. To run this service locally we need to configure some variables. So run the following commands in a terminal:

export PORT=8000
cd src/productcatalogservice/
go build

To intercept this service we will run:

dz kube intercept --service productcatalogservice

Now if we run kubectl describe service productcatalogservice we will see that the service now has the same IP address as your Devpod. This indicates that interception was successful.

Now if you go the project url, you should see an error.

Doc Image

This is because we did not run our service locally yet. So in the productcatalogservice directory, run ./productcatalogservice This will run the service locally and now if you go to the project url you should see your service running successfully.

You can make some changes to the service and refresh the page to test your application. For example, you can remove an item from the products.json file, restart the service locally and see the change on the frontend.

Doc Image

To unintercept a service, run dz kube unintercept and it will automatically unintercept the service you intercepted.

Help / Troubleshooting #

Some other helpful commands are:

#template commands
dz kube template view
dz kube template delete
dz kube template edit

#other dz commands
dz kube list  # list running devpods
dz kube write # write local kubeconfig so you can use kubectl
dz kube ssh   # ssh into a devpod

#kubectl commands
kubectl describe pod $PODNAME
kubectl describe service $SERVICENAME

Use the --help flag to know more about the commands and the available flags.

PreviousStatic IPs
NextKubernetes Overview