← Back to homek8s

Deploying Kubernetes Pods with Minikube: A Step-by-Step Guide

← All writing

Introduction

Kubernetes is the go-to container orchestration platform, and Minikube is a great way to get started with Kubernetes on your local machine. Whether you’re a DevOps engineer, cloud enthusiast, or developer, this guide will walk you through deploying a Kubernetes Pod using Minikube and kubectl.

By the end of this guide, you’ll know how to:

✅ Install and set up Minikube and kubectl

✅ Deploy a Kubernetes Pod using a pod.yml file

✅ Use kubectl commands to manage and troubleshoot Pods

✅ Access a deployed Pod using curl

Let’s get started! 🚀

GitHub Repository

You can find all the code examples used in this guide in my GitHub repository:

🔗 GitHub Repo

Step 1: Installing Minikube

Minikube allows you to run Kubernetes locally. If you’re on macOS (Apple Silicon), follow these steps:

1️⃣ Install Minikube

Use Homebrew to install Minikube:

brew install minikube

2️⃣ Verify the Installation

Check if Minikube is installed correctly:

minikube version

3️⃣ Start Minikube

Make sure Docker Desktop is running (if using Docker as the driver), then start Minikube:

minikube start --driver=docker

If Docker isn’t available, you can use another virtualization driver:

minikube start --driver=virtualization

Step 2: Installing kubectl

kubectl is the command-line tool for interacting with your Kubernetes cluster.

1️⃣ Install kubectl Using Homebrew

brew install kubectl

2️⃣ Verify Installation

kubectl version --client

Now, you’re ready to deploy a Pod! 🚀

Step 3: Deploying a Kubernetes Pod

1️⃣ Ensure Minikube is Running

Before deploying, confirm that Minikube is active:

minikube status

2️⃣ Deploy the Pod Using kubectl apply

Navigate to the directory where your pod.yml file is located and run:

kubectl apply -f pod.yml

3️⃣ Example pod.yml File

Here’s a sample configuration for deploying an Nginx Pod:

apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

Step 4: Managing Pods with kubectl

Once your Pod is running, you can use kubectl commands to monitor and manage it.

1️⃣ Check Pod Status

kubectl get pods

2️⃣ Get Detailed Information About a Pod

kubectl describe pod nginx

This command provides detailed status, events, and logs related to the Pod.

3️⃣ View Pod Logs

kubectl logs nginx

4️⃣ Delete a Pod

kubectl delete pod nginx

5️⃣ Access the Pod’s Terminal

kubectl exec -it nginx -- /bin/bash

6️⃣ Get Cluster Information

kubectl cluster-info

7️⃣ List All Nodes in the Cluster

kubectl get nodes

Step 5: Accessing the Minikube Dashboard

Minikube provides a built-in Kubernetes dashboard for visualization. Open it with:

minikube dashboard

This will launch the dashboard in your browser, allowing you to monitor and manage your cluster visually.

Step 6: Exposing the Pod and Accessing It via curl

1️⃣ Get Minikube’s IP Address

minikube ip

2️⃣ Expose the Pod as a Service

To make your Pod accessible externally, create a NodePort service:

kubectl expose pod nginx --type=NodePort --port=80

3️⃣ Get the Assigned NodePort

kubectl get service nginx

4️⃣ Use curl to Access the Pod

Now, you can access your running Nginx server using curl.

• Replace <Minikube_IP> with the output of minikube ip.

  • Replace <NodePort> with the assigned port from kubectl get service nginx.
curl http://<Minikube_IP>:<NodePort>

Example Usage

If:

• minikube ip returns 192.168.49.2

• The NodePort assigned is 30080

Then, the command would be:

curl http://192.168.49.2:30080

If successful, you’ll see the default Nginx welcome page returned as HTML output. 🎉

Step 7: Troubleshooting Common Issues

🔹 Minikube Not Starting?

✅ Ensure Docker Desktop is running

✅ Try restarting with:

minikube delete
minikube start --driver=docker

🔹 Pod Stuck in ContainerCreating?

✅ Check logs with:

kubectl describe pod nginx

✅ Make sure the Nginx image exists and there are no network issues.

🔹 curl Not Working?

✅ Ensure the NodePort service is exposed correctly.

✅ Run:

kubectl get service nginx

✅ Verify Minikube’s IP and port.

Conclusion

By following this guide, you have successfully:

✅ Installed Minikube and kubectl

✅ Deployed a Kubernetes Pod using a YAML file

✅ Used essential kubectl commands to manage the Pod

✅ Exposed the Pod as a NodePort service

✅ Accessed the Pod using curl

What’s Next?

💡 Explore Kubernetes Deployments for better scalability.

💡 Use Ingress Controllers for advanced routing.

💡 Experiment with Kubernetes ConfigMaps and Secrets for dynamic configurations.

Kubernetes opens up endless possibilities for container orchestration. Now that you’ve got your first Pod running, keep experimenting and scaling your knowledge! 🚀

🚀 Let’s Connect!

If you found this guide helpful, follow me for more DevOps and Cloud Engineering content:

🔗 GitHubgithub.com/Dhanika-Kumarasiri

🔗 Mediummedium.com/@dhanika-kumarasiri

Have questions? Drop them in the comments! Let’s automate AWS the smart way! 🚀

Originally published on Medium.

Read on Medium