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 aK8s
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. Thespec
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 therobot-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.