Das Traurigste am Leben ist, dass die Wissenschaft derzeit schneller Wissen sammelt als die Gesellschaft Weisheit.  — Isaac Asimov

Inspiration:

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


Damit der Zugriff über den Ingress funktioniert modifizieren wir die Services wie folgt:

alfred@pc1:~/metallb$ kubectl get ingress --all-namespaces
NAMESPACE   NAME                 CLASS    HOSTS            ADDRESS     PORTS   AGE
default     name-based-ingress   <none>   k8s.slainte.at   127.0.0.1   80      115s
default     hello-ingress        <none>   *                127.0.0.1   80      115s
alfred@pc1:~/metallb$

# Name base
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: name-based-ingress
  namespace: default
  annotations:
  # Class checken mit kubectl -n ingress describe daemonset.apps/nginx-ingress-microk8s-controller
  #  kubernetes.io/ingress.class: public
  #  nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: public
    ingress.kubernetes.io/rewrite-target: /      
spec:
  rules:
  - host: k8s.slainte.at
    http:
      paths:
      - path: /hello
        pathType: Prefix
        backend:
          service:
            name: hello-service
            port:
              number: 80
      - path: /foo
        pathType: Prefix
        backend:
          service:
            name: foo-service
            port:
              number: 80
alfred@pc1:~/metallb$
 

alfred@bureau:~$ curl -k http://192.168.0.210
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.19.2</center>
</body>
</html>

alfred@bureau:~$ curl -k http://192.168.0.210/hello
Hostname: hello-app-dep-85f96595c9-9tb62
IP: 127.0.0.1
IP: ::1
IP: 10.1.169.6
IP: fe80::68da:83ff:fe50:d451
RemoteAddr: 10.1.146.70:58066
GET /hello HTTP/1.1
Host: 192.168.0.210
User-Agent: curl/7.68.0
Accept: */*
X-Forwarded-For: 192.168.0.202
X-Forwarded-Host: 192.168.0.210
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Real-Ip: 192.168.0.202
X-Request-Id: 2f81024b4931b9d18c711e7d622b3e47
X-Scheme: http

alfred@bureau:~$ curl -k http://192.168.0.210/foo
Hostname: foo-app-dep-7f9dc4d867-nfq44
IP: 127.0.0.1
IP: ::1
IP: 10.1.169.4
IP: fe80::e8af:4fff:fe48:44
RemoteAddr: 10.1.169.3:50170
GET /foo HTTP/1.1
Host: 192.168.0.210
User-Agent: curl/7.68.0
Accept: */*
X-Forwarded-For: 10.1.146.64
X-Forwarded-Host: 192.168.0.210
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Real-Ip: 10.1.146.64
X-Request-Id: 7c136f25ae8fc8d24b9fccfac4ec4d0f
X-Scheme: http

alfred@bureau:~$ curl -k http://k8s.slainte.at/hello
Hostname: hello-app-dep-85f96595c9-c2522
IP: 127.0.0.1
IP: ::1
IP: 10.1.100.3
IP: fe80::5022:31ff:fede:2f15
RemoteAddr: 10.1.146.70:52304
GET /hello HTTP/1.1
Host: k8s.slainte.at
User-Agent: curl/7.68.0
Accept: */*
X-Forwarded-For: 192.168.0.202
X-Forwarded-Host: k8s.slainte.at
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Real-Ip: 192.168.0.202
X-Request-Id: a00822eef75326cd0d36edafb568fe51
X-Scheme: http

alfred@bureau:~$ curl -k http://k8s.slainte.at/foo
Hostname: foo-app-dep-7f9dc4d867-zgmcw
IP: 127.0.0.1
IP: ::1
IP: 10.1.169.5
IP: fe80::f0d6:15ff:fe15:a8af
RemoteAddr: 10.1.212.231:37570
GET /foo HTTP/1.1
Host: k8s.slainte.at
User-Agent: curl/7.68.0
Accept: */*
X-Forwarded-For: 10.1.146.64
X-Forwarded-Host: k8s.slainte.at
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Real-Ip: 10.1.146.64
X-Request-Id: cc7acc0e9629bc06018dfe853987ef74
X-Scheme: http