Implementing Ingress Controllers and Resources

In Kubernetes, Ingress is a powerful resource that manages external access to services within a cluster, typically HTTP and HTTPS traffic. Instead of exposing applications using NodePort or LoadBalancer for each service, Ingress provides a centralized way to configure routing, SSL termination, and load balancing. To use Ingress, you need an Ingress Controller, which is the actual implementation that processes Ingress rules.

Ingress Controllers

An Ingress Controller is a Pod or set of Pods that interpret Ingress resources and configure the underlying load balancer or proxy. Kubernetes does not come with a built-in Ingress Controller; you must deploy one.

Popular Ingress Controllers

  • NGINX Ingress Controller: Most widely used, supports advanced routing and SSL termination.
  • HAProxy Ingress: High-performance ingress with advanced load balancing.
  • Traefik: Lightweight ingress controller with dynamic configuration.
  • Cloud Provider Ingress: GCP, AWS, and Azure provide their own ingress integrations.

Installing NGINX Ingress Controller

# Using Helm
helm repo add ingress-nginx `https://kubernetes.github.io/ingress-nginx` [(kubernetes.github.io in Bing)](https://www.bing.com/search?q="https%3A%2F%2Fkubernetes.github.io%2Fingress-nginx")
helm repo update
helm install my-ingress ingress-nginx/ingress-nginx

Explanation: This installs the NGINX Ingress Controller into your cluster using Helm.

Ingress Resources

An Ingress Resource defines rules for routing external traffic to internal services. It specifies hostnames, paths, and backend services.

YAML Example: Basic Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: demo-ingress
spec:
  rules:
  - host: demo.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: demo-service
            port:
              number: 80

Explanation: This Ingress routes traffic from demo.example.com to the demo-service on port 80.

Flowchart: Ingress Workflow


   Client request ---> Ingress Controller ---> Matches Ingress rules
          |
          v
   Routes traffic ---> Backend Service ---> Target Pods
  

Advanced Ingress Features

  • SSL/TLS Termination: Ingress can handle HTTPS traffic by referencing TLS secrets.
  • Path-based Routing: Direct traffic to different services based on URL paths.
  • Host-based Routing: Route traffic based on domain names.
  • Rewrite Rules: Modify request paths before forwarding.
  • Load Balancing: Distribute traffic across multiple Pods.

YAML Example: TLS Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: tls-ingress
spec:
  tls:
  - hosts:
    - secure.example.com
    secretName: tls-secret
  rules:
  - host: secure.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: secure-service
            port:
              number: 443

Explanation: This Ingress uses a TLS secret to enable HTTPS traffic for secure.example.com.

Real-Time Example

In a SaaS platform:

  • Ingress Controller: NGINX manages routing for multiple microservices.
  • Ingress Resource: Routes auth.example.com to the authentication service and api.example.com to the API service.
  • TLS: Provides secure HTTPS connections for all customer-facing endpoints.

Common Mistakes

  • Not deploying an Ingress Controller—Ingress resources alone do nothing.
  • Misconfiguring hostnames, causing routing failures.
  • Forgetting to create TLS secrets for HTTPS traffic.
  • Using NodePort instead of Ingress for complex routing scenarios.

Interview Notes

Q1: What is the difference between Ingress and Service?

Answer: A Service exposes Pods internally or externally, while Ingress provides advanced routing, SSL termination, and centralized traffic management.

Q2: Why do we need an Ingress Controller?

Answer: Ingress resources define rules, but the Ingress Controller enforces them by configuring the underlying proxy or load balancer.

Q3: How do you enable HTTPS in Ingress?

Answer: Create a TLS secret with certificates and reference it in the Ingress resource.

Q4: Example Interview Task

# Create TLS secret
kubectl create secret tls tls-secret --cert=cert.pem --key=key.pem

# Apply Ingress with TLS
kubectl apply -f tls-ingress.yaml

Explanation: This sequence creates a TLS secret and applies an Ingress resource for HTTPS traffic.

Advanced Notes

  • Ingress + Cert-Manager: Automates TLS certificate management using Let’s Encrypt.
  • Ingress Annotations: Provide fine-grained control (timeouts, rewrites, rate limiting).
  • Ingress with External DNS: Automatically updates DNS records for Ingress hosts.
  • Best Practices: Use Ingress for centralized routing, enable TLS, and monitor Ingress Controller logs.

Summary

Ingress Controllers and Resources provide a scalable way to manage external traffic in Kubernetes. Controllers like NGINX or Traefik enforce Ingress rules, while resources define routing, SSL termination, and load balancing. By mastering Ingress, developers can build secure, production-ready applications with centralized traffic management. Avoiding common mistakes and understanding advanced features prepares professionals for real-world deployments and interviews.