Day 31: 90DaysOfChallenge

Day 31: 90DaysOfChallenge

Launching your First Kubernetes Cluster with Nginx running

  • What is minikube?

Minikube is a tool that quickly sets up a local Kubernetes cluster on macOS, Linux, and Windows, allowing deployment either as a VM, container, or on bare-metal. It provides all the benefits of Kubernetes with considerably less effort. With Minikube, one can experiment with Kubernetes without needing a big setup. It's great for beginners who are just getting started with containers and for projects involving edge computing or the Internet of Things.

  • Features of minikube.

The features of Minikube explained are:

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

(b) Works on different operating systems like Linux, macOS, and Windows.

(c) Can be set up as a virtual machine, a container, or directly on your computer's hardware.

(d) Supports different ways of running containers, like CRI-O, containerd, or Docker.

(e) Has a direct way to interact with its API, which makes loading and building images super fast.

(f) Comes with advanced options like LoadBalancer, letting you manage networking and storage easily.

(g) Offers additional features, called addons, that allows to install extra apps on your Kubernetes setup with ease.

(h) Works smoothly with common continuous integration (CI) setups, helping you automate testing and deployment.

  • What is Pod?

In Kubernetes, a pod is the smallest thing you can create and manage. It includes all the containers that need to run your application, as well as shared resources like storage and network settings. These containers inside a pod always run together, share resources, and are treated as one unit. So, if one container in a pod needs to talk to another, they can easily do so because they're all part of the same pod.

  • Task - 01: Install minikube on your local.

Minikube can run a Kubernetes cluster either in a VM or locally via Docker. Hence, firstly we need to install docker, and then minikube. We also need to install kubectl which is a Kubernetes command-line tool. Let's go through each of the installation process, step by step.

  1. Login to your AWS account and launch an EC2 instance with Instance type selected as t2.medium

  2. Launch the instance and wait for it to get started.

  3. Once, the instance is running, connect it using SSH. Here, I have used Putty for connection.

  4. Update Package Repositories -

    Run the below command to update package Repositories:

     sudo apt update -y
    

  5. Install Docker -

    Run the below command to install docker

     sudo apt install docker.io
    

  6. Check Docker version -

    Run the below command to check whether docker is installed or not:

     docker --version
    

  7. Grant docker permission -

    Add the user to Docker Group so that permission is granted for user to use docker commands without sudo.

     sudo usermod -aG docker $USER
    

  8. Check user added in Docker Group -

    Check whether user is added or not using the below command -

     cat /etc/group
    

  9. Reboot the system

    Reboot to apply the changes using the below command -

     sudo reboot
    
  10. Install Minikube -

    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/
    

  11. 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"
    

    Make it executable and move it into your path:

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

  12. Start Minikube -

    Now, you can start Minikube with the below command:

    minikube start --driver=docker
    

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

  13. Check Cluster Status -

    Check the cluster status with the below command:

    minikube status
    

  14. You can also use kubectl to interact with your cluster:

    kubectl get nodes
    

  • Task - 02: Create your first pod on Kubernetes through minikube.

  1. Create a YAML file named nginx-pod.yaml and enter the below code-

     apiVersion: v1
     kind: Pod
     metadata:
       name: nginx
       namespace: nginx
     spec:
       containers:
         - name: nginx
           image: nginx:1.14.2
           ports:
         - containerPort: 80
    
  2. Apply command is used to initialize the configuration written in the YAML file. Use the below code to create the pod:

     kubectl apply -f nginx-pod.yaml
    

  3. Verify that the Pod is running using the below command:

     kubectl get pods
    

    We can see nginx pod is up and running in the above screenshot.

  4. Check the status of minikube container using docker ps as below -

  5. Stop Minikube -

    You can stop the Minikube cluster using the below command:

     minikube stop
    

  6. Delete Minikube Cluster -

    You can delete the Minikube cluster using the below command:

     minikube delete
    

    Hurray! We have installed Minikube on our local and created our first Pod on Kubernetes through Minikube.

    Thanks for reading!

    Happy Learning!