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.
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/htmlBuild 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:latestStep 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: 80Apply the deployment:
kubectl apply -f nginx-deployment.yamlStep 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: ClusterIPApply the service:
kubectl apply -f nginx-service.yamlStep 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: 80Apply the Ingress resource:
kubectl apply -f nginx-ingress.yamlStep 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 ingressConclusion
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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
