Minikube: Deploying Microservices

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

In this hands-on lab we will be deploying microservices to our Minikube cluster. We will deploy the robot-shop example application into its own name space, and then ensure that all of the services are started and running. Once that is done, we will access the robot-shop application via proxy and ensure that it is working as expected.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Start the Minikube Cluster Using the Correct Driver

Run the command:

sudo minikube start --vm-driver none
Deploy Robot-Shop in Its Own Namespace

In the user’s home directory, there is a robot-shop directory, and within it a K8s subdirectory. Let’s get into it:

cd ~/robot-shop/K8s

Now that we’re there, we can create a namespace for the resources:

sudo kubectl create namespace robot-shop

Then we can create the resources in the namespace:

sudo kubectl -n robot-shop apply -f ./descriptors/

Let’s monitor the pods to ensure that they come up:

sudo kubectl -n robot-shop get po -w

Once all of the pods have come up this task is complete.

Edit the Web Service, Configure the Proxy, and Test the Application

Let’s take a closer look at the web service:

sudo kubectl -n robot-shop get svc web

Its TYPE is currently LoadBalancer, and that’s not what we want here. We need to edit the web service and change its type to NodePort:

sudo kubectl -n robot-shop edit svc web

We’ll land in a vim session. The spec section should look like this (minus the comments) when we’re done:

spec:
 ports:
 - name: "8080"
   port: 8080
   protocol: TCP
   targetPort: 8080
   nodePort: 30080    <-- ensure that the nodePort it set to this value
 selector:
   service: web
 sessionAffinity: None
 type: NodePort    <---- change from LoadBalancer

Now let’s take another look at the web service:

sudo kubectl -n robot-shop get svc web

Its TYPE should be NodePort now.

Now let’s get the URL of the web service:

sudo minikube service list

We need the TARGET_PORT of the web service for this next step. We’ve got to edit the Nginx configuration and set the port forwarding to the NodePort URL:

sudo vim /etc/nginx/sites-enabled/default

    location / {
               # First attempt to serve request as file, then
               # as directory, then fall back to displaying a 404.
               proxy_pass http://<minikube IP>:<svc port>;

Once that’s done, we can restart Nginx:

sudo systemctl restart nginx

Finally, we can test in a web browser. If we exit in the terminal, we’ll get the server’s public IP. We can also get it from the hands-on lab overview page. But browse to it, and we should see the robot-shop application up and running. Feel free to tool around and look at the different robots. If you can, it means we’re through setting things up.

Additional Resources

Different groups in our company simply cannot agree on a common technology. Each department wants to use the latest and greatest solution to their particular issue. This means that we will need to ensure that each of the technologies can be integrated into one cluster and deployed as microservices. As a proof of concept, we have decided to deploy the robot-shop application stack into our Minikube cluster. It needs to be in its own namespace, and it should be accessible from the outside world via a web browser.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?