๐ŸŽฏ What It Is

Path-based routing allows a single domain to serve multiple apps based on the URL path โ€” e.g.,

โœ… This is essential for microservices, monorepos, and cost-efficient hosting.

๐Ÿ’ก Real-World Analogy

Like a shopping mall directory:


๐Ÿงช Example: Route Paths to Different Services

Assume you have:

Step 1: Create an Ingress with Path Rules

# path-routing.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
meta
  name: app-ingress
spec:
  rules:
  - host: myapp.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: frontend
            port:
              number: 80

      - path: /api
        pathType: Prefix
        backend:
          service:
            name: api
            port:
              number: 80

      - path: /docs
        pathType: Prefix
        backend:
          service:
            name: docs
            port:
              number: 80

Apply it:

kubectl apply -f path-routing.yaml

Step 2: Test the Paths

# Get Ingress IP (Traefik in k3s)
INGRESS_IP=$(kubectl get svc -n kube-system traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}')

# Add to /etc/hosts (for local testing)
echo "$INGRESS_IP myapp.com" | sudo tee -a /etc/hosts

# Test paths
curl <http://myapp.com/>        # โ†’ frontend
curl <http://myapp.com/api>     # โ†’ api
curl <http://myapp.com/docs>    # โ†’ docs