Minikube is a lightweight local Kubernetes engine for macOS, Linux, and Windows. You can use Minikube as a test bed, or if you are new to Kubernetes, explore how to configure and deploy pods. In this post, I will explain how to install Minikube on Ubuntu 22.04, and I will teach you how to take your first steps with Kubernetes.
Avatar
Latest posts by Edem Afenyo (see all)

Prerequisites

Ensure your local setup meets the following minimum requirements:

  • This article uses Ubuntu 22.04. You can also install Minikube on Windows, macOS, or any other Linux flavor.
  • Your host machine should at least meet the following requirements for a fluid experience:
    • 2+ CPUs
    • 2 GB+ RAM
    • At least 20 GB free disk space
  • In this guide, we will work with Docker (v20.10.22). However, any other container or virtual machine manager, such as Hyper-V or Podman, will also do.

Install Minikube on Ubuntu

With all the prerequisites in place, you can now install Minikube as described below.

Open a terminal emulator and download the Minikube binary:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

During the download, you should have a progress report on your screen, as in the screenshot below.

Downloading Minikube

Downloading Minikube

Next, install the binary on your machine with the command below:

sudo install minikube-linux-amd64 /usr/local/bin/minikube 

Starting a Kubernetes cluster on Minikube

With Minikube installed, spin up a new cluster with the following command:

minikube start

Minikube will start with a cluster in a Docker container, as in the screenshot below. In the output, you should notice the versions of Docker and Kubernetes your cluster employs, along with the cluster's specs. Wait until you see that the setup is Done!

Starting Minikube

Starting Minikube

You can alter the specs of the Minikube container to provide the right amount of room for your workloads. Getting into Minikube itself is a topic for another post. For now, let's focus on getting started with Kubernetes.

Now that your cluster is up and running, you can explore Kubernetes in earnest. The first thing to do, just to ensure everything is okay, is to list all (-A) available pods with Kubectl. Kubectl is the standard tool for interacting with Kubernetes clusters.

kubectl get pods –A

The response should be a list of Kubernetes system-related pods with corresponding statuses, as shown below. Since you have not started a pod of your own, the list should contain only pods that Kubernetes needs for optimal functioning.

Listing available pods

Listing available pods

Starting a pod

You can now create a deployment for your first pod. In Kubernetes terminology, a pod is a container that is slightly modified to be managed in a Kubernetes environment. For this tutorial, you can create a deployment called my-nginx using the latest nginx image:

kubectl create deployment my-nginx --image=nginx:latest

You can confirm the state of the pod with Kubectl as shown below. Add the -w switch to watch the progress of the pod as it is being created.

kubectl get pod -w

As you can see in the screenshot below, the pod is up and running.

Watching the start of a pod

Watching the start of a pod

To return to the command prompt, hit <ctrl+c>.

Scaling a deployment

One great Kubernetes feature is the ability to scale the number of pods in a deployment up or down, sometimes automatically, in response to demand. You can scale the my-nginx deployment to two pods as follows:

kubectl scale deployment my-nginx --replicas=2

Confirm that another pod has been added to the cluster:

kubectl get pods

Notice the difference in the names of the pods, confirming that they are two different entities. If, for example, you are using this setup as a web server, both pods will respond to client requests.

Scaling a deployment

Scaling a deployment

Stopping pods

Kubernetes was also created to be self-healing. This means that once a pod is created as part of a deployment, you cannot stop it by merely killing the pod. If a pod is terminated for any reason, Kubernetes will recreate it to satisfy the deployment requirements.

One way to effectively remove the pods of a particular service from your cluster is to delete the deployment that caused its creation in the first place, as in the snippet below:

kubectl delete deployment my-nginx

You can confirm that all the nginx pods have been stopped with kubectl:

kubectl get pods
Confirming the deletion of a deployment

Confirming the deletion of a deployment

Alternatively, you can stop pods by reducing the number of replicas in a deployment. Reducing the scale to zero essentially removes all pods from the deployment. Of course, this method is not as clean as deleting the deployment because the deployment remains active.

Stopping the Minikube Cluster

Stop and power off the cluster as shown below:

minikube stop
Stopping Minikube

Stopping Minikube

Stopping a cluster keeps some settings and files related to the cluster on disk and allows you to restore as much of the state of the cluster when you restart Minikube later. What happens if you want to reset your cluster and start over? Stopping the cluster will not help. Well, that's where deletion comes in.

Deleting a cluster

Deleting clusters is helpful when you want to start fresh with default settings or make certain changes to the cluster. Deletion also helps you conserve disk space that would otherwise have been occupied by the container or virtual machine that hosts a cluster.

You can delete a cluster with the delete subcommand as follows:

minikube delete

As usual, you should see a summary of the steps taken to delete the cluster, as in the screenshot below:

Subscribe to 4sysops newsletter!

Deleting a cluster

Deleting a cluster

Conclusion

Minikube enables you to learn and test out numerous Kubernetes features from the comfort of your local machine. You can go as far as running multinode clusters in Minikube. Are you a developer who wants to make your application Kubernetes ready, or a sysadmin who wants to transition to platform engineering? Kubernetes on Minikube might be the next step to take.

avataravatar
0 Comments

Leave a reply

Please enclose code in pre tags: <pre></pre>

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account