#Day 31 : Installation of minikube on local &  Kubernetes Cluster with Nginx running

#Day 31 : Installation of minikube on local & Kubernetes Cluster with Nginx running

What is minikube?

Minikube is a tool which quickly sets up a local Kubernetes cluster on macOS, Linux, and Windows. It can deploy as a VM, a container, or on bare-metal.

Minikube is a pared-down version of Kubernetes that gives you all the benefits of Kubernetes with a lot less effort.

This makes it an interesting option for users who are new to containers, and also for projects in the world of edge computing and the Internet of Things.

Features of minikube -

(a) Supports the latest Kubernetes release (+6 previous minor versions)

(b) Cross-platform (Linux, macOS, Windows)

(c) Deploy as a VM, a container, or on bare-metal

(d) Multiple container runtimes (CRI-O, containerd, docker)

(e) Direct API endpoint for blazing fast image load and build

(f) Advanced features such as LoadBalancer, filesystem mounts, FeatureGates, and network policy

(g) Addons for easily installed Kubernetes applications

(h) Supports common CI environments

Task-01: Install minikube on your local

Minikube Installation Guide for Ubuntu

This guide provides step-by-step instructions for installing Minikube on Ubuntu. Minikube allows you to run a single-node Kubernetes cluster locally for development and testing purposes.

Pre-requisites

  • Ubuntu OS

  • sudo privileges

  • Internet access

  • Virtualization support enabled (Check with egrep -c '(vmx|svm)' /proc/cpuinfo, 0=disabled 1=enabled)


Step 1: Update System Packages

Update your package lists to make sure you are getting the latest version and dependencies.

sudo apt update

image

Step 2: Install Required Packages

Install some basic required packages.

sudo apt install -y curl wget apt-transport-https

image


Step 3: Install Docker

Minikube can run a Kubernetes cluster either in a VM or locally via Docker. This guide demonstrates the Docker method.

sudo apt install -y docker.io

image

Start and enable Docker.

sudo systemctl enable --now docker

Add current user to docker group (To use docker without root)

sudo usermod -aG docker $USER && newgrp docker

Now, logout (use exit command) and connect again.


Step 4: Install Minikube

First, download the Minikube binary using curl:

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

Make it executable and move it into your path:

chmod +x minikube
sudo mv minikube /usr/local/bin/

image


Step 5: Install kubectl

Download kubectl, which is a Kubernetes command-line tool.

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

Check above image ⬆️ Make it executable and move it into your path:

chmod +x kubectl
sudo mv kubectl /usr/local/bin/

image


Step 6: Start Minikube

Now, you can start Minikube with the following command:

minikube start --driver=docker

This command will start a single-node Kubernetes cluster inside a Docker container.


Step 7: Check Cluster Status

Check the cluster status with:

minikube status

You can also use kubectl to interact with your cluster:

kubectl get nodes

Step 8: Stop Minikube

When you are done, you can stop the Minikube cluster with:

minikube stop

Optional: Delete Minikube Cluster

If you wish to delete the Minikube cluster entirely, you can do so with:

minikube delete

That's it! You've successfully installed Minikube on Ubuntu, and you can now start deploying Kubernetes applications for development and testing.

Task-02:

Create your first pod on Kubernetes through minikube.

Let's understand the concept pod

Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.

A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers. A Pod's contents are always co-located and co-scheduled, and run in a shared context. A Pod models an application-specific "logical host": it contains one or more application containers which are relatively tightly coupled.

To create your first pod on Kubernetes using Minikube, follow these steps:

  1. Install Minikube: If you haven't already, you'll need to install Minikube on your system. You can find installation instructions for your specific platform here: Minikube Installation Guide.

  2. Start Minikube: Open a terminal and start Minikube by running the following command:

     minikube start
    

    This command will create a new Minikube cluster. It may take a few minutes to complete.

  3. Verify Cluster: You can verify that Minikube is running correctly by using the following command:

     minikube status
    

    It should show that Minikube is running and the kubectl context is set to the Minikube cluster.

  4. Create a Pod: Now, you can create a simple Pod using a YAML configuration file. Here's an example YAML file named my-pod.yaml for a basic NGINX web server Pod:

     apiVersion: v1
     kind: Pod
     metadata:
       name: nginx
     spec:
       containers:
         - name: nginx-container
           image: nginx:latest
    

    Save this YAML file on your system.

  5. Apply the Pod Configuration: Apply the Pod configuration to your Minikube cluster using kubectl:

     kubectl apply -f my-pod.yaml
    

    This will create the Pod in your Minikube cluster.

  6. Check Pod Status: You can check the status of your Pod using the following command:

     kubectl get pods
    

    It should show the status of your my-nginx-pod Pod as "Running" after a brief moment.

  7. Access the Pod: To access the NGINX web server running in your Pod, you need to expose it as a service. You can use the following command to create a NodePort service:

     kubectl expose pod nginx --type=NodePort --port=80
    
  8. Find the Port: Find the NodePort assigned to your service:

     kubectl get svc
    

    Look for the "PORT(S)" column, and you'll find a port number (e.g., 30080) that maps to port 80 on your Pod.

  9. Access the NGINX Web Server: You can access the NGINX web server in your Pod by opening a web browser and navigating to http://<minikube-ip>:<NodePort>. To get the Minikube IP, use:

     minikube ip
    

    Replace <minikube-ip> with the IP address and <NodePort> with the NodePort number you found in step 8.

That's it! You've created your first Pod on Minikube and accessed a simple NGINX web server running inside the Pod. You can further customize and manage your Kubernetes resources as needed for your applications.