DEV Community

Cover image for Part-108: 🚀Kubernetes Ingress – Context Path Based Routing in Google Kubernetes Engine
Latchu@DevOps
Latchu@DevOps

Posted on

Part-108: 🚀Kubernetes Ingress – Context Path Based Routing in Google Kubernetes Engine

When running multiple applications in Kubernetes, exposing them through different LoadBalancers becomes costly and hard to manage.
This is where Ingress comes in – it allows path-based routing, so a single LoadBalancer can serve multiple applications.

In this guide, we’ll deploy 3 Nginx apps in GKE and configure Ingress so that:

  • /app1/* → routes to app1 service
  • /app2/* → routes to app2 service
  • /* → routes to app3 service (default)

i1


🟢 Step-01: Introduction

We will:

  1. Deploy App1, App2, App3 with Nginx containers.
  2. Expose them via NodePort services.
  3. Configure a single Ingress with path-based rules.

🟡 Step-02: Deploy App1, App2 & App3

🔹 app1-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app1-nginx-deployment
  labels:
    app: app1-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app1-nginx
  template:
    metadata:
      labels:
        app: app1-nginx
    spec:
      containers:
        - name: app1-nginx
          image: ghcr.io/stacksimplify/kube-nginxapp1:1.0.0
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: app1-nginx-nodeport-service
spec:
  type: NodePort
  selector:
    app: app1-nginx
  ports:
    - port: 80
      targetPort: 80
Enter fullscreen mode Exit fullscreen mode

🔹 app2-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app2-nginx-deployment
  labels:
    app: app2-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app2-nginx
  template:
    metadata:
      labels:
        app: app2-nginx
    spec:
      containers:
        - name: app2-nginx
          image: ghcr.io/stacksimplify/kube-nginxapp2:1.0.0
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: app2-nginx-nodeport-service
spec:
  type: NodePort
  selector:
    app: app2-nginx
  ports:
    - port: 80
      targetPort: 80
Enter fullscreen mode Exit fullscreen mode

🔹 app3-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app3-nginx-deployment
  labels:
    app: app3-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app3-nginx
  template:
    metadata:
      labels:
        app: app3-nginx
    spec:
      containers:
        - name: app3-nginx
          image: ghcr.io/stacksimplify/kubenginx:1.0.0
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: app3-nginx-nodeport-service
spec:
  type: NodePort
  selector:
    app: app3-nginx
  ports:
    - port: 80
      targetPort: 80
Enter fullscreen mode Exit fullscreen mode

🔹 ingress-cpr.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-cpr
  annotations:
    kubernetes.io/ingress.class: "gce"   # GKE Ingress Controller
spec:
  defaultBackend:
    service:
      name: app3-nginx-nodeport-service
      port:
        number: 80
  rules:
    - http:
        paths:
          - path: /app1
            pathType: Prefix
            backend:
              service:
                name: app1-nginx-nodeport-service
                port:
                  number: 80
          - path: /app2
            pathType: Prefix
            backend:
              service:
                name: app2-nginx-nodeport-service
                port:
                  number: 80
Enter fullscreen mode Exit fullscreen mode

🟣 Step-04: Deploy & Verify

# Apply manifests
kubectl apply -f ingress/

# Check pods
kubectl get pods

# Check services
kubectl get svc

# Check Ingress
kubectl get ingress
kubectl describe ingress ingress-cpr
Enter fullscreen mode Exit fullscreen mode

👉 Wait 3–5 minutes for the LoadBalancer to be created.

i2


🔴 Step-05: Access the Applications

Once the LoadBalancer is ready, check the ADDRESS field in Ingress output.

http://<INGRESS-ADDRESS>/app1/index.html
http://<INGRESS-ADDRESS>/app2/index.html
http://<INGRESS-ADDRESS>/
Enter fullscreen mode Exit fullscreen mode

i3


🟠 Step-06: Verify in Google Cloud Console

Go to:

➡️ Load Balancing → Click on the LoadBalancer → Explore tabs:

  • DETAILS: Frontend, Host/Path rules, Backend services, Health checks
  • MONITORING: Traffic & Latency
  • COMPONENTS: Forwarding rules, Target proxies, Certificates

i4


🟤 Step-07: Clean Up

kubectl delete -f ingress/
Enter fullscreen mode Exit fullscreen mode

i5


✅ Summary

  • We deployed 3 Nginx apps.
  • Exposed them via NodePort Services.
  • Configured Ingress for context path routing.
  • Verified traffic routing through a single GKE LoadBalancer.

This is one of the most common real-world patterns for microservices routing in Kubernetes 🎯.


🌟 Thanks for reading! If this post added value, a like ❤️, follow, or share would encourage me to keep creating more content.


— Latchu | Senior DevOps & Cloud Engineer

☁️ AWS | GCP | ☸️ Kubernetes | 🔐 Security | ⚡ Automation
📌 Sharing hands-on guides, best practices & real-world cloud solutions

Top comments (0)