π Deploy Nginx on Kubernetes using Minikube


Sections:
π Introduction
Kubernetes has become the standard for container orchestration, and Minikube makes it easy to run Kubernetes locally.
In this project, Iβve deployed an Nginx web server on Kubernetes using Minikube.
π‘ Why Kubernetes + Nginx?
Kubernetes: Automates container deployment, scaling, and management.
Nginx: A lightweight, high-performance web server.
Together, they provide a fast, scalable, and easily deployable web solution.
π What is Minikube?
Minikube is a lightweight Kubernetes implementation that runs on your local machine. Itβs perfect for:
Learning Kubernetes
Testing workloads before production
Rapid prototyping
β Prerequisites
Make sure you have:
A system with at least 4 GB RAM
kubectl installed
Docker installed
Minikube installed
β Install Minikube
Follow the official guide for your OS:
Minikube Installation Guide
β Install kubectl & Docker
kubectl: CLI to interact with Kubernetes
Install kubectlDocker: Container runtime for Minikube
Install Docker
π Step 1: Start Minikube Cluster
minikube start
This spins up a local Kubernetes cluster inside a VM or Docker container.
π Step 2: Create Deployment
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
π Explanation:
apiVersion: Kubernetes API version for Deployment.
kind: Resource type (Deployment).
metadata: Name of the Deployment.
replicas: Number of Nginx pods.
selector: Labels to identify pods.
template: Pod template containing:
containers: List of containers (Nginx in this case).
image: Docker image to use.
ports: Port inside the container.
π Step 3: Expose Service
service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30080
π Explanation:
type: NodePort: Exposes the service on each node's IP at a static port.
selector: Matches pods with label
app=nginx
.ports: Defines port mapping.
port: Port exposed by the service.
targetPort: Container's port.
nodePort: External port for access.
π Step 4: Access the App
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
minikube service nginx-service
This will open the Nginx welcome page in your browser.
π§ Troubleshooting
Pods not starting
kubectl get pods kubectl describe pod <pod-name>
Check image pull errors or YAML syntax.
Port not accessible
Make sure NodePort (e.g.,30080
) is open and not blocked by a firewall.
π Conclusion + GitHub Link
We successfully deployed Nginx on Kubernetes using Minikube.
You can find the complete project files here:
https://github.com/Harshalv21/nginx-minikube-k8s-demo.git
Credits
Tutorial inspired by Kubernetes official documentation and community resources.
Subscribe to my newsletter
Read articles from HARSHAL VERNEKAR directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

HARSHAL VERNEKAR
HARSHAL VERNEKAR
π Aspiring DevOps & Cloud Engineer with a strong foundation in cloud platforms (AWS), infrastructure automation, and container orchestration tools like Docker and Kubernetes. Iβm passionate about building reliable, scalable, and secure cloud-native applications. π§ Currently building real-world projects using Terraform, Ansible, Jenkins, GitHub Actions, and EKS to understand how modern infrastructure is deployed, managed, and monitored. I enjoy breaking things (safely), debugging, and learning from hands-on experience. π¦ Comfortable working with: AWS (EC2, S3, IAM, VPC, EKS) Docker, Kubernetes (Minikube & EKS) CI/CD tools like Jenkins & GitHub Actions IaC tools like Terraform & Ansible Monitoring with Prometheus & Grafana Linux, Bash, Git, and Networking fundamentals π‘ Always learning β currently exploring deeper concepts in Kubernetes workloads, Helm, and scaling best practices. π Open to DevOps, Cloud, or SRE roles where I can grow, contribute, and solve real-world problems.