1) Pods are ephemeral — deployment example
Create a Deployment namedweb (nginx) with three replicas:
172.17.0.6) will lose connectivity. This is the primary reason we use Services.
2) ClusterIP service (internal cluster access)
Expose theweb Deployment as a ClusterIP service named web-svc on port 80:
kubectl describe svc web-svc:
- ClusterIP is internal-only (accessible from inside the cluster).
- The Service uses selectors (labels) to discover matching pods — the Deployment assigned the label
app=web.
3) NodePort service (external access for labs or single-node)
If you need external access in a lab or single-node environment (without a cloud load balancer), use NodePort:localhost if running locally):
Ingress provides host-based and path-based routing, and TLS termination. It requires an Ingress controller to implement the routing (for example, nginx-ingress, Traefik, or other controllers).
4) Ingress controller — verify it’s running
This lab uses the nginx ingress controller in namespaceingress-nginx. Verify controller pods and service:
- In cloud environments the controller’s Service is often type
LoadBalancerwith an external IP. - In labs it may be
NodePort, which exposes controller ports on the node(s).
5) Create a second service — api
Create an api Deployment using HashiCorp’s http-echo image to return a simple message. Use the --command flag to pass container arguments:
kubectl port-forward to confirm it returns the message.
6) Create an Ingress resource to route to both services
Create an Ingress manifest (for exampleingress.yaml) that routes /api to api-svc:5678 and / to web-svc:80. Example:
7) Test routing via the ingress controller NodePort
Use the controller NodePort (for example30080) to test both routes:
- Root
/should route toweb-svc(NGINX welcome page). /apishould route toapi-svcand return the echo message.
curl localhost:30080/returns the NGINX welcome HTML.curl localhost:30080/apireturns:
8) The three-layer relationship
Understand the three-layer architecture and responsibilities:- Ingress: external routing, host/path matching, TLS termination (external entry point).
- Service: stable internal discovery and load balancing (virtual IP / DNS for a set of pods).
- Pod: the actual workload (ephemeral compute).
- Can’t reach the app externally? Check the Ingress resource and the Ingress controller.
- Ingress appears fine but routing is wrong? Re-check the Ingress rules and annotations.
- Service has no endpoints? Verify pod labels/selectors and pod readiness.
- Pod-level issues? Inspect pod logs and readiness/liveness probes.
Troubleshooting checklist
Ingress resources require a running Ingress controller. Creating an Ingress without a controller will not provide routing traffic. In cloud environments you may get a LoadBalancer service automatically for the controller; in labs you often use NodePort.
Links and references
- Kubernetes Services: https://kubernetes.io/docs/concepts/services-networking/service/
- Ingress and Ingress Controllers: https://kubernetes.io/docs/concepts/services-networking/ingress/
- nginx-ingress Controller: https://kubernetes.github.io/ingress-nginx/
- Traefik Ingress Controller: https://traefik.io/
- HashiCorp http-echo: https://github.com/hashicorp/http-echo