Kubernetes Ingress can’t find a Service in a different namespace
An Ingress backend refers to a Service by name only, and Kubernetes looks for that name in the Ingress’s own namespace. A Service with the right name in another namespace is not found.
Here the Ingress is in the frontend namespace and the Service is in backend. The traffic check shows the break between them. Move the Ingress into backend in the editor and the path connects.
Will traffic reach the Pods?
Ingress api.example.com/does not reachService api:80. Service "api" is in namespace "backend", but this Ingress is in "frontend" and looks for it there. Fix: Put the Ingress and the Service in the same namespace.Service api:80connects toDeployment api:8080.
What this manifest does
This manifest defines 3 resources across 2 namespaces: the main thing it runs is 1 Deployment. Let’s walk through it.
Deployment api runs 2 Pods, running myorg/api:1.4.2.
A Service (api) gives these Pods a stable cluster-internal address.
Things to know before using it
Backend Service isn’t in this manifestIngress api
This Ingress routes to a Service not defined here:
api. If the Service is also missing in the cluster, requests will return 503 / default backend. Fix: Confirm the backend Service exists in the same namespace and the names match exactly.No topology spread or anti-affinityDeployment api
Deployment "api" has 2 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
# The Ingress is in "frontend". The Service it names is in "backend".
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: api
namespace: frontend
spec:
ingressClassName: nginx
tls:
- hosts: [api.example.com]
secretName: api-tls
rules:
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api
port:
number: 80
---
apiVersion: v1
kind: Service
metadata:
name: api
namespace: backend
spec:
selector:
app: api
ports:
- port: 80
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
namespace: backend
spec:
replicas: 2
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: myorg/api:1.4.2
ports:
- containerPort: 8080
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: 8080
livenessProbe:
httpGet:
path: /healthz
port: 8080
Stuck on a Kubernetes concept?
Ask anything and get a narrated visual lesson, pitched at your level. Free.
Try an example