Cloud Native 5 min read

Deploy a Frontend Nginx App on Kubernetes with Ingress in 5 Steps

This guide walks you through setting up a Kubernetes cluster, building and pushing a custom Nginx Docker image, creating Deployment, Service, and Ingress resources, and verifying external access to the frontend application.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Deploy a Frontend Nginx App on Kubernetes with Ingress in 5 Steps

Introduction

Kubernetes (K8s) is an open‑source container orchestration platform that automates deployment, scaling, and management of applications. This tutorial shows how to deploy a frontend Nginx image on K8s and expose it externally using an Ingress resource.

Prerequisites

A Kubernetes cluster (local Minikube or a cloud‑provided cluster).

The kubectl command‑line tool installed and configured.

Docker installed for building and pushing images.

Step 1: Build the Nginx Image

Create a Dockerfile with the following content:

FROM nginx:alpine
COPY . /usr/share/nginx/html

Build and push the image to Docker Hub (or a private registry):

docker build -t your-dockerhub-username/nginx-frontend:latest .
docker push your-dockerhub-username/nginx-frontend:latest

Step 2: Create the Kubernetes Deployment

Save the following as nginx-deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-frontend
  template:
    metadata:
      labels:
        app: nginx-frontend
    spec:
      containers:
      - name: nginx
        image: your-dockerhub-username/nginx-frontend:latest
        ports:
        - containerPort: 80

Apply the deployment:

kubectl apply -f nginx-deployment.yaml

Step 3: Create the Service

Save the following as nginx-service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx-frontend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: ClusterIP

Apply the service:

kubectl apply -f nginx-service.yaml

Step 4: Configure Ingress

Create nginx-ingress.yaml with the following content:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: your-domain.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx-service
            port:
              number: 80

Apply the Ingress resource:

kubectl apply -f nginx-ingress.yaml

Step 5: Verify the Deployment

Access the application via http://your-domain.com. You should see the Nginx welcome page if everything is configured correctly. You can also inspect the resources with:

kubectl get deployments
kubectl get services
kubectl get ingress

Conclusion

By following these steps you have learned how to build a Dockerized Nginx frontend, deploy it on Kubernetes, expose it through a Service, and configure an Ingress for external access, leveraging the powerful features of K8s for containerized applications.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeDeploymentKubernetesNginxIngress
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.