Launching Your First Kubernetes Cluster with Minikube and Running Nginx

Urvish SuhagiyaUrvish Suhagiya
3 min read

Introduction to Minikube

Minikube is a lightweight Kubernetes implementation that creates a VM on your local machine and deploys a simple cluster containing only one node. It is an excellent tool for developers to experiment with Kubernetes and learn how it works without needing a full-fledged cluster.

Why Use Minikube?

  • Quick Setup: Minikube provides a quick and easy way to set up a local Kubernetes cluster.

  • Cross-Platform: It works on macOS, Linux, and Windows.

  • Flexible Deployment: Deploy as a VM, container, or on bare-metal.

  • Supports Latest Kubernetes Releases: Stay up-to-date with the latest features and updates.

  • Multiple Container Runtimes: Supports CRI-O, containerd, and Docker.

Step-by-Step Guide to Launch Your First Kubernetes Cluster

Install Minikube

To install Minikube, you can follow the instructions on the official Minikube start page. Here’s a brief overview:

  1. Download Minikube:

     curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
     sudo install minikube /usr/local/bin/
    
  2. Start Minikube:

     minikube start
    

Minikube will set up a local Kubernetes cluster for you. Once it’s up and running, you can interact with your cluster using kubectl.

Understand the Concept of Pods

In Kubernetes, a Pod is the smallest deployable unit. It can contain one or more containers that share storage and network resources. Pods encapsulate the application containers, storage resources, a unique network IP, and options that govern how the container(s) should run.

Key Features of Pods:

  • Single or Multiple Containers: A Pod can have one or more containers.

  • Shared Storage and Network: Containers within a Pod share the same storage and network resources.

  • Application-Specific Host: Represents a logical host for running application containers.

For more detailed information about Pods, you can refer to the Kubernetes Pods Documentation.

Create Your First Pod with Nginx

We will create a Pod that runs an Nginx container. Here’s how you can do it:

  1. Create a YAML file for the Pod:

     # nginx-pod.yaml
     apiVersion: v1
     kind: Pod
     metadata:
       name: nginx-pod
     spec:
       containers:
       - name: nginx
         image: nginx:latest
         ports:
         - containerPort: 80
    
  2. Apply the YAML file to create the Pod:

     kubectl apply -f nginx-pod.yaml
    
  3. Verify that the Pod is running:

     kubectl get pods
    

    You should see an output similar to this:

     NAME         READY   STATUS    RESTARTS   AGE
     nginx-pod    1/1     Running   0          10s
    
  4. Access the Nginx container:

     minikube service nginx-pod --url
    

    This command will provide a URL that you can visit in your web browser to see the Nginx welcome page.

Conclusion

By following these steps, you have successfully set up a local Kubernetes cluster using Minikube and deployed an Nginx container inside a Pod. This hands-on experience is crucial for understanding how Kubernetes works and will serve as a solid foundation for further exploration and learning.

Minikube simplifies the process of learning and experimenting with Kubernetes, making it an invaluable tool for developers and DevOps engineers. Keep experimenting, and you'll soon master the art of container orchestration with Kubernetes!

Happy Learning! 😊

2
Subscribe to my newsletter

Read articles from Urvish Suhagiya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Urvish Suhagiya
Urvish Suhagiya

Exploring the world of DevOps 🌐.