Skip to content

Kubernetes Ingress routing rules

Kubernetes Ingress is an API object that manages external access to services within a cluster, typically through HTTP/HTTPS.^[400-devops-06-kubernetes-devops-helm-helm-jenkins-todo.md] It functions as a layer 7 (application layer) load balancer and entry point for traffic, routing requests to specific backend services based on defined rules.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__TODO.md]

Ingress Resource Specification

An Ingress resource is defined using networking.k8s.io/v1 as the apiVersion and Ingress as the kind.^[400-devops-06-kubernetes-devops-helm-helm-jenkins-todo.md] The core behavior of the Ingress is dictated by the spec section, which includes the Ingress class and the routing rules themselves.

Configuration Example

The following example demonstrates a basic Ingress configuration using the NGINX Ingress class to route traffic based on a specific hostname^[400-devops-06-kubernetes-devops-helm-helm-jenkins-todo.md]:

apiVersion: networking.k8s.io/v1
kind: [Ingress](<./ingress.md>)
metadata:
  name: myapp-ing
spec:
  ingressClassName: nginx
  rules:
    - host: "yudady.ml"
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: myapp-svc
                port:
                  number: 80

Routing Rules

Routing logic is defined within the rules list of the Ingress specification^[400-devops-06-kubernetes-devops-helm-helm-jenkins-todo.md]. Each rule can map a hostname to a specific path configuration.

Host and Path

A rule typically associates a specific host (e.g., yudady.ml) with a list of http paths^[400-devops-06-kubernetes-devops-helm-helm-jenkins-todo.md]. Inside the paths list, you define the following:

  • path: The URL path that the request must match (e.g., /).
  • pathType: Determines how the path matching is interpreted. The example uses Prefix, which matches based on a URL path prefix split by /^[400-devops-06-kubernetes-devops-helm-helm-jenkins-todo.md].
  • backend: The destination for the traffic, defined by the service name and the port number^[400-devops-06-kubernetes-devops-helm-helm-jenkins-todo.md].

Sources

  • 400-devops-06-kubernetes-devops-helm-helm-jenkins-todo.md
  • 400-devops__06-Kubernetes__devops-helm__helm-jenkins__TODO.md