H 141: Setup minikube and kubectl (15 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 Bootcamp (CKAD) .

Preparation

First do the previous project, "Hello Kubernetes".

Starting Minikube

On your Linux server, execute these commands:

minikube start
Your cluster starts, showing several messages, ending with "Done! kubectl is now configured...", as shown below.

Troubleshooting

If minkube just hangs and won't start, press Ctrl+C and execute these commands:

minikube delete
minikube start

Examining minikube Status

On your Linux server, execute these commands:

minikube status
You should see several "Running" items, as shown below.

Create kubectl alias and Enable Autoconpletion

This will create an alias so you can use the command "kubectl" instead of "minikube kubectl --".

It will also enable autocompletion, so you can use the Tab key to fill in commands.

Execute these commands:


cd
nano .bashrc
Scroll to the bottom of the file and add these lines, as shown below:

# minikube kubectl
alias kubectl='minikube kubectl --'
source <(kubectl completion bash)

Save the file with Ctrl+c, y, Enter.

Execute this command to make the new alias effective:


source .bashrc

Using the Alias

Execute these commands:

kubectl version
kubectl get all
You see version numbers, and a single service running, as shown below.

Viewing the kubectl Help Page

Execute this command:

kubectl help
Read through the list. There aren't very many commands.

Choosing a Text Editor

The default kubectl edit text editor is vi. If you prefer nano, as I do, execute this command:

export KUBE_EDITOR="nano"

Getting your Server's IP Address

Execute this command:

ip a
Note the IP address that goes to the host system, highlighted in the image below:

Launching the minikube Dashboard

Execute this command:

minikube dashboard --url=false &
Press Enter again to get a new $ prompt.

Then execute this command:


kubectl proxy --address 0.0.0.0 --disable-filter=true &
Press Enter again to get a new $ prompt.

Then execute this command:


sudo ss -pantl
The "kubectl" process is listening on all interfaces on port 8001, as shown at the bottom of the image below.

Note: this is an unsafe way to expose the dashboard.

On your host system, in a Web browser, open this URL, replacing the IP address with the IP address of your server:

http://192.168.121.152:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
You see the Dashboard, as shown below.

Deploying a Webserver Cluster

In the Dashboard, at the top right, click the plus-sign, outlined in red in the image above.

Click the "Create from form" tab.

In the form, enter these values:

Below the Service line, enter these values: At the bottom, click the blue Deploy button, as shown below.

You see a "Workload Status" page. After a few seconds, the circles turn green, as shown below.

In the Kubernetes dashboard, in the left pane, in the Workloads section, click Pods.

You have three containers running, as shown below.

In the Kubernetes dashboard, click Service.

The "app" service is running, with a Type of "LoadBalancer", as shown below.

Starting a Port Forwarder

Execute this command:

kubectl get all
You see pods, services, deployments, and a replicaset, as shown below.

To make "service/app" accessible from outside the Kubernetes virtual network, you have to start a port forwarder.

Execute this command:


minikube kubectl --  port-forward service/app 7080:8080 --address=0.0.0.0 &
Press Enter to get a fresh $ prompt, as shown below.

Flag H 141.1: Viewing the App (10 pts)

On your host system, in a Web browser, open this URL, replacing the IP address with the IP address of your server:
http://192.168.121.152:7080
The flag is covered by a green rectangle in the image below.

Observing Replication

Let's delete one of the pods.

Execute this command:


kubectl get all
Copy the name of the first pod, highlighted in the image below.

Execute these commands to delete that pod, and view resources again. Replace the name in the first command with the correct name of your pod.


kubectl delete pod pod/app-6b4d7fb9c6-vrkf9
kubectl get all 
A new pod appears, only a few seconds old, to replace the deleted one, as shown below.

Cleaning Up: Deleting the Deployment

Execute these commands:

kubectl get all
kubectl delete deploy app
kubectl get all
The pods, deployments, and replicaset vanish, as shown below.

Cleaning Up: Deleting the Service

Execute these commands:

kubectl delete service app
kubectl get all
The service is gone, as shown below.

Deleting the Kubernetes Service

Execute these commands:

kubectl delete service kubernetes
kubectl get all 
If you see nothing, wait a few seconds and execute the "kubectl get all" command again.

The kubernetes service is automatically recreated, replicaset, as shown below.

References

Kubernetes Bootcamp (CKAD)

Posted 3-10-25
Updated with exercises after the flag 3-12-25