What Is an Ingress?

An Ingress is a Kubernetes object that manages external access to Services in the cluster. An Ingress is capable of providing more functionality than a simple NodePort Service, such as

  1. SSL termination,
  2. Advanced load balancing
  3. Name-based virtual hosting.

Ingress objects actually do nothing by themselves. In order for Ingresses to do anything, you must install one or more Ingress controllers. There are a variety of Ingress Controllers available, all of which implement different methods for providing external access to your Services.

Routing to a Service

Ingresses define a set of routing rules. A routing rule’s properties determine to which requests it applies. Each rule has a set of paths, each with a backend. Requests matching a path will be routed to its associated backend.

In this example, a request to http://<some-endpoint>/somepath would be routed to port 80 on the my-service Service.

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

Routing to a Service with a Named Port

If a Service uses a named port, an Ingress can also use the port’s name to choose to which port it will route.

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
  - name: web
    protocol: TCP
    port: 80
    targetPort: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
  - http:
      paths:
      - path: /somepath
        pathType: Prefix
        backend:
          service:
            name: my-service
            port:
              name: web