🚀 Day 31 Launching First Kubernetes Cluster with Nginx running
Welcome back! Today’s task is all about hands-on Kubernetes*! After learning about Kubernetes' architecture in the previous task, it's time to implement it locally and see it in action.
In this guide, we'll introduce Minikube and help you create your very first Kubernetes pod. By the end, you'll have Nginx running in a Kubernetes cluster on your local machine. Let’s get started! 🎉
🎯 What is Minikube?
Minikube is a tool that makes it super easy to set up a local Kubernetes cluster on macOS, Linux, and Windows. With Minikube, you don’t need a complex cloud setup. Instead, you get a simpler, lightweight version of Kubernetes that’s perfect for testing, learning, and even experimenting with small projects.
Why Use Minikube?
Minikube is an excellent choice for beginners and those who want to experiment with Kubernetes without needing a massive infrastructure. It’s also ideal for edge computing and IoT projects.
🔍 Key Features of Minikube
Minikube offers some fantastic features that make it both versatile and powerful:
🆕 Supports Latest Kubernetes Releases: It’s always up-to-date with the latest Kubernetes versions.
🌍 Cross-Platform: Works on Linux, macOS, and Windows.
💻 Flexible Deployment: Run it as a VM, a container, or on bare metal.
🧰 Multiple Container Runtimes: Works with CRI-O, containerd, and Docker.
⚡ Fast API Endpoints: Quickly loads and builds images.
🔧 Advanced Features: Includes LoadBalancer, filesystem mounts, network policies, and more!
➕ Addons: Easily install Kubernetes applications.
🤖 CI Support: Works well in continuous integration environments.
Ready to dive in? Let’s begin with setting up Minikube! 🔥
🛠️ Task 01: Install Minikube
To get started, let’s install Minikube on your local machine. Follow the steps below based on your operating system:
Visit the Official Installation Page: Head over to Minikube’s installation page and select your OS (Linux, macOS, or Windows).
here below download for Ubuntu/Linux:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64
Follow the Instructions: Minikube provides simple installation commands for each platform. Copy the commands and paste them into your terminal.
Verify the Installation: Once Minikube is installed, type the following command to check that it’s working:
minikube version
Start Minikube: Now, start Minikube with:
minikube start
⚙️ Alternative Method: You can also install Minikube using package managers like Homebrew for macOS, Chocolatey for Windows, or by downloading the binary directly. Visit this alternative installation page for details.
🤔 Understanding Pods in Kubernetes
Before creating a pod, let's briefly discuss what a pod is.
In Kubernetes, a Pod is the smallest deployable unit. Think of it as a small "container group" that holds one or more containers. These containers share resources like storage and network, making it easier for them to work together.
🔹 Pods as "Logical Hosts": A pod can be seen as a tiny host that contains tightly-coupled application containers.
🔹 Sharing Resources: All containers in a pod share network and storage resources, which allows for smooth communication and data sharing between them.
Want to learn more? Check out this detailed guide on Kubernetes pods.
🛠️ Task 02: Create Your First Pod on Kubernetes Using Minikube
Now, let’s get hands-on and create our first Kubernetes pod! For this task, we'll create an Nginx pod, which is a popular web server and a great first step to learning Kubernetes.
Step-by-Step Guide to Creating an Nginx Pod
Open Your Terminal: Make sure Minikube is running with:
minikube status
If Minikube is not running, start it with:
minikube start
Create an Nginx Pod: Run the following command to create a new Nginx pod.
kubectl run nginx-pod --image=nginx --restart=Never
This command:
Creates a pod named
nginx-pod
Uses the
nginx
image to deploy the web serverSets
--restart=Never
to ensure Kubernetes does not automatically restart the pod if it stops.
Verify the Pod Status: Check if the pod is running by typing:
kubectl get pods
You should see
nginx-pod
with a status ofRunning
.Access the Nginx Pod: Forward the port to access Nginx on your local browser.
kubectl port-forward nginx-pod 8080:80
Now, open a browser and go to
http://localhost:8080
. You should see the default Nginx welcome page! 🎉Clean Up: Once you’re done, delete the pod to free up resources.
kubectl delete pod nginx-pod
🎉 Wrapping Up
Congratulations! You just launched your first Kubernetes cluster with Minikube and deployed an Nginx pod. Here’s what we covered today:
🚀 What Minikube is and why it’s perfect for local Kubernetes clusters.
⚙️ Installing Minikube on your local machine.
🤔 Understanding the concept of Pods in Kubernetes.
🛠️ Creating and running your first Nginx pod on Minikube.
With these hands-on steps, you’re now familiar with deploying applications on Kubernetes locally. This is just the beginning—there’s so much more to explore in the world of Kubernetes! 🌍
Stay tuned for the next task, and keep experimenting! Remember, practice makes perfect. 👏
Subscribe to my newsletter
Read articles from Dhruv Moradiya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by