K8S Ingress - klagan/learning GitHub Wiki

Getting started

What is Ingress?

Ingress exposes HTTP and HTTPS routes form outside the cluster to services within the cluster. Traffic routing is controlled by the Ingress resource. Essentially the ingress resource defines the rules the ingress controller will implement.

What is an Ingress controller?

source

An ingress controller is a specialised load balancer.

  • Accept traffic from outside the Kubernetes platform, and load balance it to pods (containers) running inside the platform
  • Can manage egress traffic within a cluster for services which need to communicate with other services outside of a cluster
  • Are configured using the Kubernetes API to deploy objects called “Ingress Resources”
  • Monitor the pods running in Kubernetes and automatically update the load‑balancing rules when pods are added or removed from a service

Installing an ingress controller

source

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.4/deploy/static/provider/cloud/deploy.yaml

Deploy an ingress resource

source

The following example routes all traffic to port 80 on the sample-webapi service.

apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: sample-webapi
    annotations:
      kubernetes.io/ingress.class: nginx
      nginx.ingress.kubernetes.io/ssl-redirect: "false"
      nginx.ingress.kubernetes.io/use-regex: "true"
      nginx.ingress.kubernetes.io/rewrite-target: /$1
  spec:
    rules:
    - http:
        paths:
        - path: /(.*)
          pathType: Prefix
          backend:
            service:
              name: sample-webapi
              port: 
                number: 80

This example routes traffic on a route of /testpath to port 80 on the service test.

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

Adding TLS with LetsEncrypt

# add the cert-manager
helm repo add jetstack https://charts.jetstack.io
helm repo update

# install custom resource definitions (crd)
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.5.4/cert-manager.crds.yaml

# install cluster issuer

⚠️ **GitHub.com Fallback** ⚠️