8th Week :- "Why Kubernetes Services Fall Short in DevOps – And How Ingress Solves It

Lav kushwahaLav kushwaha
4 min read

🚫 Problem: Why Kubernetes Services Alone Are Not Ideal for Production

In Kubernetes, a Service is used to expose a set of Pods as a network service. It ensures that traffic is correctly routed to healthy pods using a stable IP address or DNS name. There are mainly three types of Services:

  1. ClusterIP – accessible only within the cluster (default)

  2. NodePort – exposes service on a static port on each node

  3. LoadBalancer – creates an external load balancer (on supported cloud providers)

❌ Drawbacks of Using Just Services

ProblemExplanation
Multiple LoadBalancers = $$$Every time you use type: LoadBalancer for a microservice, your cloud provider provisions a separate external load balancer – increasing costs drastically.
No URL RoutingServices don’t allow routing based on URL paths or hostnames. You can't route example.com/api to backend and example.com to frontend.
No SSL ManagementServices don't handle SSL/TLS certificates and HTTPS routing natively.
Hard to Maintain DNSWithout URL/host-based routing, managing domains and subdomains becomes a mess.
No Central Entry PointEach service gets its own entry point (IP/port), making it hard to manage ingress traffic from outside the cluster.

✅ Solution: Ingress + Ingress Controller

🌐 What is Ingress?

Ingress is an API object in Kubernetes that acts as an entry point to your cluster. It allows you to route external HTTP and HTTPS traffic to internal services based on:

  • Hostnames (example.com)

  • Paths (/api, /frontend)

  • TLS settings

Think of Ingress as a smart router for your Kubernetes apps.

🧠 What is Ingress Controller?

Ingress rules alone don’t do anything. You need an Ingress Controller, which is a pod running in your cluster that watches the Ingress objects and fulfills the routing.

Popular Ingress Controllers:

  • NGINX Ingress Controller

  • HAProxy Ingress

  • Traefik

  • Istio Gateway (part of service mesh)

Among these, NGINX is the most widely used due to its simplicity and flexibility.


🧾 Sample Ingress YAML File (Using NGINX)

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: myapp.example.com
      http:
        paths:
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: backend-service
                port:
                  number: 5000
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend-service
                port:
                  number: 80

🧩 Breakdown of Ingress YAML

SectionDescription
apiVersionVersion of the Ingress API
kindType of Kubernetes object (Ingress)
metadata.nameName of the Ingress object
annotationsExtra config for NGINX, like path rewrite
spec.rules.hostDomain name this rule applies to
pathsList of routes under that host
pathTypePrefix or Exact match for the path
backend.service.nameThe service name to route to
port.numberPort of that service

📦 Step-by-Step Example: Deploy Backend and Frontend with Ingress

🎯 Use Case

You have two services:

  • Frontend (React/Vue) served on /

  • Backend (Express/Django) served on /api

1️⃣ Backend Deployment YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
spec:
  replicas: 2
  selector:
    matchLabels:
      app: backend
  template:
    metadata:
      labels:
        app: backend
    spec:
      containers:
        - name: backend
          image: your-dockerhub/backend:latest
          ports:
            - containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
  name: backend-service
spec:
  selector:
    app: backend
  ports:
    - protocol: TCP
      port: 5000
      targetPort: 5000
  type: ClusterIP

2️⃣ Frontend Deployment YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
spec:
  replicas: 2
  selector:
    matchLabels:
      app: frontend
  template:
    metadata:
      labels:
        app: frontend
    spec:
      containers:
        - name: frontend
          image: your-dockerhub/frontend:latest
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: frontend-service
spec:
  selector:
    app: frontend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: ClusterIP

3️⃣ Ingress YAML File (Same as Above)

Ensure your domain (myapp.example.com) is pointing to your cluster’s LoadBalancer IP.


⚙️ Setting up NGINX Ingress Controller

✅ Step 1: Install via Helm

bashCopyEdithelm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update

helm install nginx-ingress ingress-nginx/ingress-nginx \
  --set controller.publishService.enabled=true

✅ Step 2: Get External IP

bashCopyEditkubectl get svc -n ingress-nginx

Look for the EXTERNAL-IP of the nginx-ingress-controller and point your domain (myapp.example.com) to it using DNS.


☁️ How This Works in a Cloud Provider

  1. You deploy the backend and frontend via kubectl apply -f deployment.yml.

  2. You install the Ingress Controller (NGINX).

  3. You create an Ingress resource with routing rules.

  4. Your cloud provider provisions a LoadBalancer for the Ingress Controller.

  5. You map your domain to that LoadBalancer IP.

  6. Incoming requests are handled by the Ingress Controller and routed based on your rules.

✅ Final Thoughts

❌ Services Alone✅ Ingress
Expensive with LoadBalancerCost-efficient single LoadBalancer
No routing logicURL + Host-based smart routing
No SSL/TLSBuilt-in HTTPS support
Poor scalabilityDesigned for production-grade traffic

Ingress is an essential part of production-ready Kubernetes clusters. It reduces costs, simplifies networking, improves maintainability, and is crucial for DevOps success in cloud deployments.

0
Subscribe to my newsletter

Read articles from Lav kushwaha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Lav kushwaha
Lav kushwaha