Damit sich das Nginx-Deployment auch von außen errreichen lässt, also nicht nur innerhalb des Raspberry Pi, müssen Sie noch einen sogenannten NodePort hinzufügen (Listing 4). Nun können Sie die Nginx-Anwendung auch aus dem heimischen WLAN erreichen. Um das zu testen, setzen Sie von jedem Host im eigenen Funknetzwerk einfach den Befehl curl 127.0.0.1:30178 ab. Dies sollte eine Ausgabe ähnlich der aus Listing 5 erzeugen. In diesem Fall haben Sie nun eine funktionierende Microk8s-Installation am Start und können jede Menge spannende Experimente machen.
Listing 4
Exponieren eines Kubernetes-Diensts
$ microk8s.kubectl expose deployment my-nginx --port 80 --name my-nginx-np --type NodePort service/my-nginx-np exposed $ microk8s.kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 47h my-nginx-np NodePort 10.152.183.73 <none> 80:30178/TCP 13s $ microk8s.kubectl get all NAME READY STATUS RESTARTS AGE pod/my-nginx-9b596c8c4-4jp7d 1/1 Running 0 3m34s pod/my-nginx-9b596c8c4-7ql2q 1/1 Running 0 3m34s pod/my-nginx-9b596c8c4-ngd2q 1/1 Running 0 17m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 47h service/my-nginx-np NodePort 10.152.183.73 <none> 80:30178/TCP 20s NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/my-nginx 3/3 3 3 17m NAME DESIRED CURRENT READY AGE replicaset.apps/my-nginx-9b596c8c4 3 3 3 17m
Listing 5
Nginx-Deployment validieren
$ curl RasPiIP:30178
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Fazit
Kubernetes ist zwar recht recht komplex, aber das Ubuntu-Snap Microk8s lässt sich verhältnismäßig einfach installieren und erlaubt spannende Experimente mit einem Mini-Cluster, der im Prinzip bereits so funktioniert wie in einem Rechenzentrum. Ein solches Projekt kann über den Lerneffekt hinaus auch tatsächlich nützliche Applikationen skalierbar und hochverfügbar machen. Dank des Raspberry Pi hält sich dabei der finanzielle Aufwand noch in Grenzen. (jlu)
Infos
- Raspberry Pi 4: https://www.raspberrypi.org/products/raspberry-pi-4-model-b/
- Microk8s: https://microk8s.io
- Clound Native Computing Foundation: https://www.cncf.io
- Kubernetes: https://kubernetes.io
- USB-C-Netzteil: https://www.raspberrypi.org/products/type-c-power-supply/
- Ubuntu für Raspberry Pi: https://ubuntu.com/download/raspberry-pi
- Ubuntu-Image für ARM64: https://ubuntu.com/download/raspberry-pi/thank-you?version=20.04.4&architecture=server-arm64+raspi
- Microk8s installieren: https://ubuntu.com/tutorials/install-a-local-kubernetes-with-microk8s#2-deploying-microk8s
- Microk8s-Dokumentation: https://microk8s.io/docs/
- Microk8s lokal nutzen: https://kubernetes.io/blog/2019/11/26/running-kubernetes-locally-on-linux-with-microk8s/
- Nginx: https://nginx.org





