What is an Ingress controller in Kubernetes?

Ingress is a Kubernetes resource that is used to route external traffic. It routes this traffic to the services in our Kubernetes cluster depending on the rules defined by the user. An Ingress controller is responsible for implementing the Ingress resource.

There are various Ingress controllers available, including but not limited to the following:

  • Nginx Ingress controller

  • HAProxy Ingress controller

  • Traefik Ingress controller

Example

We'll use the "traefik" Ingress controller for this Answer. The traefik Ingress controller watches for Ingress resources and provides dynamic configuration capabilities. This means it can automatically configure and route the incoming traffic to the services by updating its routing rules.

# Create an Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-demo-ingress
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: nginx-demo-service
                port:
                  number: 8080
---
# Create a Service

apiVersion: v1
kind: Service
metadata:
  name: nginx-demo-service
spec:
  selector:
    app: nginx
  ports:
  - port: 8080
    targetPort: 80

---
# Create a Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-demo-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx-demo-container
Creating the Kubernetes resources

Click the "Run" button on the widget above to create a k3d Kubernetes cluster consisting of a single node.

Note: The Kubernetes cluster creation will a couple minutes to complete.

Once done, it's time to create a Kubernetes Deployment, Service, and an Ingress object. The widget above contains a resources.yaml manifest. This file contains the definitions of the Kubernetes Deployment, Service, and Ingress objects. A detailed explanation of this file is provided below:

Code explanation

  • Lines 3, 23, and 37: We define the Kubernetes API version that we’ll use to create the Deployment, Service, and Ingress objects, i.e., v1, apps/v1, and networking.k8s.io/v1.

  • Lines 4, 24, and 38: We define the types of objects that will be created, i.e.,  Ingress, service, and a Deployment object.

  • Lines 6, 26, and 40: We give a name to the objects that will be created using their respective definitions, i.e.,  nginx-demo-ingress, nginx-demo-service and nginx-demo-deployment.

  • Line 8: We specify the annotation for this Ingress object, i.e., nginx.ingress.kubernetes.io/ssl-redirect: "false". This annotation will prevent nginx from redirecting requests to https.

  • Lines 19–29: We define the rules for this Ingress. This object contains a single path with the Prefix type. This rule defines that every request we receive at / path shall be redirected to the nginx-demo-service service that is listening on the port 8080. If we want to send a request received at another path, e.g., /educative , we can do that by creating another path at line 20 with a different service name and port number.

  • Lines 29, 44, and 48: We define the labels for this Service and Deployment object, i.e., app: nginx.

  • Lines 30–32: We define the port for this Service, i.e., 8080, and the port of the nginx application, i.e., 80.

  • Lines 50–52: We define the container that will be created in the Deployment object. This container will be created using the nginx image available on DockerHub (the default container registry unless specified otherwise), and this container is named as nginx-demo-container.

To create the Deployment, Service, and an Ingress object, execute the following command:

kubectl apply -f resources.yaml

We should get an output that these resources have been created successfully.

Let's get the status of our objects using the following command:

kubectl get deployment,service,ingress,pods
# To run the Ingress on the platform, execute the following command.
# If we're working locally, we don't need this command
kubectl port-forward svc/traefik -n kube-system 3000:80 --address 0.0.0.0

If the pods are in a running state, move ahead and run the following command:

curl localhost:3000

We should see the Nginx welcome page. We can also view this welcome page from the "Output" tab or by clicking the URL provided below the SPA widget.

Unlock your potential: Kubernetes Deployment and Advanced Operations series, all in one place!

To deepen your understanding of Kubernetes deployment and management, explore our series of Answers below:

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved