panchalhimself

Ingress in kubernetes

23 June 2023

Ingress

A k8s object that manages external access to the cluster.

Can provide ssl termination, advanced load balancing, virtual routing based on name.

External Clients > Ingress managed Load Balancer [ > Ingress > Routing rule in ingress > Service in the cluster > Pods ]

the [] denote the cluster.

So routing rules are the key here, they define the rules that ingres implements.

Usually these routing rules are path based similar to the routes in a web server.

nginx-ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx-example
  rules:
  - http:
      paths:
      - path: /testpath
        pathType: Prefix
        backend:
          service:
            name: nginx-service
            port:
              number: 80

So in the above nginx-ingress.yaml the path /testpath will route the requests to the service named test inside our kubernetes cluster on port 80 of the service.

nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.18
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - name: name-of-service-port
    protocol: TCP
    port: 80
    targetPort: 80

Ingress Controllers

Service routing

NamedPort based service routing


search_query: ingress

ref: https://kubernetes.io/docs/concepts/services-networking/ingress/