Kubernetes Ingress YAML example with Service and Deployment
An Ingress routes outside HTTP traffic to a Service by name and port. The Service then forwards it to Pods by label. That makes three places where one wrong value silently breaks the path: the backend Service name, the backend port, and the selector.
This manifest wires all three correctly, with TLS on the Ingress. Change any of them in the editor and the traffic check shows the hop where requests stop.
Will traffic reach the Pods?
Ingress shop.example.com/connects toService web:80connects toDeployment web:3000.
What this manifest does
This manifest defines 3 resources in the default namespace: the main thing it runs is 1 Deployment. Let’s walk through it.
Deployment web runs 3 Pods, running myorg/web:1.4.2.
A Service (web) gives these Pods a stable cluster-internal address. Public traffic enters through an Ingress (web) at shop.example.com.
Things to know before using it
No topology spread or anti-affinityDeployment web
Deployment "web" has 3 replicas but no spread rules. All Pods could land on one node, a single failure domain. Fix: Add topologySpreadConstraints or podAntiAffinity to spread across zones/nodes.
The full manifest
# Public traffic: Ingress -> Service -> Deployment.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web
spec:
ingressClassName: nginx
tls:
- hosts: [shop.example.com]
secretName: shop-tls
rules:
- host: shop.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
---
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: myorg/web:1.4.2
ports:
- containerPort: 3000
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 256Mi
securityContext:
runAsNonRoot: true
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
readinessProbe:
httpGet:
path: /ready
port: 3000
livenessProbe:
httpGet:
path: /healthz
port: 3000
Stuck on a Kubernetes concept?
Ask anything and get a narrated visual lesson, pitched at your level. Free.
Try an example