πŸš€ 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 kubectl

  • Docker: 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.


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.

0
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.