H 140: Hello Kubernetes (20 pts)

What You Need for this Project

Purpose

To set up a Kubernetes cluster and deploy a containerized application.

I am following this tutorial .

Kubernetes Clusters

Kubernetes coordinates a highly available cluster of computers that are connected to work as a single unit.

A Kubernetes cluster consists of two types of resources:

Cluster Diagram

Nodes

A node is a VM or a physical computer that serves as a worker machine in a Kubernetes cluster.

Each node has a Kubelet, which is an agent for managing the node and communicating with the Kubernetes control plane.

A Kubernetes cluster that handles production traffic should have a minimum of three nodes to maintain high availability.

Installing Docker

Make sure your Linux machine has: On your Linux server, execute these commands, replacing "debian" in the third command with your username.

sudo apt update
sudo apt install curl docker.io -y
sudo usermod -aG docker debian
newgrp docker

Installing Minikube and Starting a Cluster

On your Linux server, execute these commands:

Note: if you are running Debian Linux on Apple silicon, replace "amd64" with "arm64" in the commands below.


curl -LO https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
rm minikube-linux-amd64
minikube start
Your cluster starts, showing several messages, ending with "Done! kubectl is now configured...", as shown below.

Examining your Cluster

On your Linux server, execute this command:

minikube kubectl -- get pods -A
You see your pods, as shown below.

Right now, all you have are system pods, to run Kubernetes, because you haven't deployed any applications.

Preparing the Dashboard

On your Linux server, execute this command:

minikube dashboard
After preparing the dashboard, it tries to open the dashboard page in your default browser, as shown below.

If you are using a headless server, it can't open a browser. Press Ctrl+C to cancel that operation, as shown below.

Serving the Dashboard on a Public IP

On your Linux server, execute this command:

minikube kubectl -- proxy --address 0.0.0.0 --disable-filter=true &
A message says "Starting to serve...", as shown below.

Press Enter to get a fresh $ prompt. The proxy process continues running in the background.

Viewing the Dashboard

In a Web browser, open this URL, replacing the IP address with the IP address of your Debian machine:

http://172.16.123.129:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
The dashboard page opens.

Flag H 140.1: Cluster (10 pts)

In the Dashboard, on the lower left, click Cluster.

The flag is covered by a green rectangle in the image below.

Examining your Cluster

On your Linux server, execute this command:

minikube kubectl -- get pods -A
Now there are two new pods, providing the dashboard, as shown below.

Deploying an Echo Server

A Kubernetes Pod is a group of one or more Containers, tied together for the purposes of administration and networking.

The Pod in this tutorial has only one Container.

A Kubernetes Deployment checks on the health of your Pod and restarts the Pod's Container if it terminates.

Deployments are the recommended way to manage the creation and scaling of Pods.

The echo server contains a Web server that simply echoes every request back to the client making it.

On your Linux server, execute these commands:


minikube kubectl --  create deployment hello-minikube --image=kicbase/echo-server:1.0
minikube kubectl --  get deployments
minikube kubectl --  get pods
minikube kubectl --  get events
You see a deployment named "hello-minikube" and a pod with a name beginning with "hello-minikube-" as shown below.

The events show the creation of the container and its assignment to the deployment.

In the Dashboard, at the top left, click Workloads.

You now have one Deployment, one Pod, and one Replica Set, as shown below.

Create a Service

By default, the Pod is only accessible by its internal IP address within the Kubernetes cluster.

To make the hello-node Container accessible from outside the Kubernetes virtual network, you have to expose the Pod as a Kubernetes Service.

On your Linux server, execute these commands:


minikube kubectl --  expose deployment hello-minikube --type=NodePort --port=8080
minikube kubectl --  get services hello-minikube
minikube kubectl --  port-forward service/hello-minikube 7080:8080 --address=0.0.0.0 &
Press Enter after the last command to get a fresh $ prompt, as shown below.

In a Web browser, open this URL, replacing the IP address with the IP address of your Debian machine:


http://172.16.123.129:7080
The echo page opens, showing the HTTP GET request that loaded it, as shown below.

Load Balancer

Now let's create a load-balanced service, which would be highly available, if we had more than one container running the service.

On your Linux server, execute these commands:


minikube kubectl --  create deployment balanced --image=kicbase/echo-server:1.0
minikube kubectl --  expose deployment balanced --type=LoadBalancer --port=8080
minikube tunnel &
minikube kubectl -- get services balanced
minikube kubectl --  port-forward service/balanced 6080:8080 --address=0.0.0.0 &
You see the "Forwarding..." message, as shown below.

Flag H 140.2: Cluster (20 pts)

In a Web browser, open this URL, replacing the IP address with the IP address of your Debian machine:

http://172.16.123.129:6080

The flag is covered by a green rectangle in the image below.

Cleaning Up

Deleting Services

On your Linux server, execute these commands:

minikube kubectl --  get services
minikube kubectl -- delete service hello-minikube
minikube kubectl -- delete service balanced
minikube kubectl --  get services
You see the two services "hello-minikube" and "balanced", and after deleting them, they are gone, as shown below.

Deleting Deployments

On your Linux server, execute these commands:

minikube kubectl --  get deployments
minikube kubectl -- delete deployment hello-minikube
minikube kubectl -- delete deployment balanced
minikube kubectl --  get deployments
You see the "Forwarding..." message, as shown below.

On your Linux server, execute this command:


minikube kubectl --  get pods
There are no more non-system pods, as shown below.

Stopping Minikube

On your Linux server, execute this command:

minikube stop

References

Learn Kubernetes Basics

Posted 3-10-25
Video added 3-11-25