1. Overview

Kubernetes is a popular open-source platform for managing containerized workloads and services. It provides a way to manage and orchestrate containerized applications, scaling them up and down as needed and ensuring they run reliably and securely.

Minikube is a tool that enables us to run a local, single-node Kubernetes cluster on our machine, which is ideal for testing and development purposes. In this tutorial, we’ll cover the steps to install and use Minikube on our local machine.

2. Prerequisites

Before we begin, we should ensure that we have the following:

  • A machine running Linux, macOS, or Windows.
  • A hypervisor, such as VirtualBox or KVM, is installed on our machine. If we’re using Windows, we can use Hyper-V instead.
  • A shell environment, such as Bash or PowerShell.
  • curl installed on our machine.

3. Installing Minikube

The first step is to install Minikube on our machine. We can do this by following the instructions provided on the Minikube website: https://minikube.sigs.k8s.io/docs/start/

Alternatively, we can use the following command to install the latest version of Minikube:

$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

This command is for Linux. If we’re using macOS or Windows, we’ll need to download the appropriate binary for our platform.

Once we’ve installed Minikube, we can verify that it’s installed correctly by running the following command:

$ minikube version 
minikube version: v1.18.1

This command outputs the version number of the Minikube binary.

4. Starting a Minikube Cluster

The next step is to start a Minikube cluster. We can do this by running the following command:

$ minikube start

This command will start a virtual machine on our local machine and configure it to run a single-node Kubernetes cluster.

The first time we run this command, it will download the necessary ISO image for the virtual machine, which can take a few minutes. Once the virtual machine is running, we can check the status of the cluster by running the following command:

$ minikube status
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
timeToStop: Nonexistent

This output shows that the Minikube control plane is running, and the kubelet and API server are also running. The kubeconfig is configured, which means that we can interact with the cluster using kubectl command. Additionally, the output also displays the status of the Minikube host machine.

5. Interacting With the Minikube Cluster

Once the cluster is up and running, we can interact with it using the kubectl command-line tool. kubectl is the primary CLI tool for interacting with Kubernetes clusters, enabling us to deploy applications, manage nodes, and perform other operations.

To use kubectl with Minikube, we must set the context to the Minikube cluster. We can do this by running the following command:

$ kubectl config use-context minikube

This command tells kubectl to use the configuration for the Minikube cluster.

We can now run kubectl commands to interact with the Minikube cluster. For example, we can run the following command to get information about the nodes in the cluster:

$ kubectl get nodes
NAME       STATUS   ROLES                  AGE    VERSION
minikube   Ready    control-plane,master   250d   v1.20.2

This command shows the list of nodes in the cluster along with their status, roles, age, and Kubernetes version.

6. Deploying an Application

To deploy an application to the Minikube cluster, we need to create a Kubernetes deployment object. A deployment object manages a set of replicas of an application and ensures that the desired state is maintained.

For this example, let’s create a simple deployment object that runs an NGINX web server. For this, we first create a file called nginx-deployment.yaml with the following contents:

apiVersion: apps/v1
kind: Deployment
  name: nginx-deployment
  replicas: 1
      app: nginx
        app: nginx
      - name: nginx
        image: nginx
        - containerPort: 80

This YAML file defines a deployment object with a single replica that runs an NGINX container. It exposes port 80 for HTTP traffic.

Then, to create the deployment, we run the following command:

$ kubectl apply -f nginx-deployment.yaml 
deployment.apps/nginx-deployment created

This command creates the deployment object in the Minikube cluster.

To access the NGINX web server, we need to expose it as a Kubernetes service. A service is an abstraction that exposes a group of pods as a network service. Let’s create a file called nginx-service.yaml with the following contents:

apiVersion: v1
kind: Service
  name: nginx-service
  type: NodePort
    app: nginx
  - name: http
    port: 80
    targetPort: 80

This YAML file defines a service object that exposes the NGINX deployment on a randomly assigned port on the virtual machine.

To create the service, we run the following command:

$ kubectl apply -f nginx-service.yaml
service/nginx-service created

We can now access the NGINX web server by getting the IP address of the virtual machine and the port number of the service:

$ minikube service nginx-service --url

This should output a URL that we can use to access the NGINX web server.

To use a locally-built Docker image in Minikube, we can simply tag the image with the Minikube Docker daemon’s IP address and push it to the Minikube Docker registry using the docker tag and docker push commands.

7. Conclusion

In this article, we covered the steps to install and use Minikube to run a local Kubernetes cluster on our machine. We also demonstrated how to deploy an application to the cluster and access it using a Kubernetes service.

Minikube is a great tool for testing and development purposes, and it enables us to get up and running with Kubernetes quickly and easily.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.