This commit is contained in:
Dominik Chilla 2020-08-23 20:34:00 +02:00
parent 5a4f77f2a2
commit 188af71caf

View File

@ -1,6 +1,14 @@
# snippets for k3s # snippets for k3s
* [Install k3s](#install-k3s) * [Install k3s](#install-k3s)
* [Disable Traefik-ingress](#disable-traefik-ingress)
* [Enable NGINX-ingress](#enable-nginx-ingress)
* [Installation](#install-nginx-ingress)
* [Change service type from NodePort to LoadBalancer](#nginx-ingress-loadbalancer)
* [Enable nginx-ingress tcp- and udp-services for apps other than http/s](#nginx-ingress-tcp-udp-enabled)
* [Deploy my-nginx-service and expose via nginx-ingress on TCP-port 9000](#deploy-and-expose-tcp-service)
* [Stick the nginx-ingress controler and my-nginx app together](#stick-nginx-ingress-and-tcp-service)
* [Test exposed app on TCP-port 9000](#test-nginx-ingress-and-tcp-service)
## Install k3s <a name="install-k3s"></a> ## Install k3s <a name="install-k3s"></a>
https://k3s.io/: https://k3s.io/:
@ -8,7 +16,7 @@ https://k3s.io/:
curl -sfL https://get.k3s.io | sh - curl -sfL https://get.k3s.io | sh -
``` ```
## Disable traeffic-ingress: ## Disable Traefik-ingress <a name="disable-traefik-ingress"></a>
edit /etc/systemd/system/k3s.service: edit /etc/systemd/system/k3s.service:
``` ```
[...] [...]
@ -16,13 +24,13 @@ ExecStart=/usr/local/bin/k3s \
server --disable traefik \ server --disable traefik \
[...] [...]
``` ```
finally `systemctl daemon-reload` and `systemctl restart k3s` Finally `systemctl daemon-reload` and `systemctl restart k3s`
## Enable nginx-ingress ## Enable NGINX-ingress <a name="enable-nginx-ingress"></a>
### Installation ### Installation <a name="install-nginx-ingress"></a>
https://kubernetes.github.io/ingress-nginx/deploy/#bare-metal https://kubernetes.github.io/ingress-nginx/deploy/#bare-metal
### Change service type from NodePort to LoadBalancer ### Change service type from NodePort to LoadBalancer <a name="nginx-ingress-loadbalancer"></a>
`kubectl edit service -n ingress-nginx` and change `type: NodePort` to `type: LoadBalancer` `kubectl edit service -n ingress-nginx` and change `type: NodePort` to `type: LoadBalancer`
Port 80 and 443 should listen now on an *External-IP* `kubectl get all --all-namespaces`: Port 80 and 443 should listen now on an *External-IP* `kubectl get all --all-namespaces`:
@ -46,7 +54,7 @@ dominik@muggler:~$ curl -s http://10.62.94.246
</html> </html>
``` ```
### Enable nginx-ingress tcp- and udp-services for apps other than http/s ### Enable nginx-ingress tcp- and udp-services for apps other than http/s <a name="nginx-ingress-tcp-udp-enabled"></a>
Docs: https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/ Docs: https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/
`kubectl edit deployment -n ingress-nginx` and search for `spec:`/`template`/`spec`/`containers` section: `kubectl edit deployment -n ingress-nginx` and search for `spec:`/`template`/`spec`/`containers` section:
@ -79,7 +87,7 @@ spec:
[...] [...]
``` ```
### Deploy my-nginx-service and expose via nginx-ingress on TCP-port 9000 ### Deploy my-nginx-service and expose via nginx-ingress on TCP-port 9000 <a name="deploy-and-expose-tcp-service"></a>
my-nginx-deployment.yml: my-nginx-deployment.yml:
``` ```
apiVersion: apps/v1 apiVersion: apps/v1
@ -157,7 +165,17 @@ spec:
<<< ADD <<< ADD
[...] [...]
``` ```
Finally, we need to glue nginx-ingress with the my-nginx app. This will be done with the config-map `tcp-services-config-map.yml` referenced earlier in the nginx-ingress deployment definition: Verify nginx-ingress is listening on port 9000 with `kubectl get all --all-namespaces`:
```
[...]
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
[...]
ingress-nginx service/ingress-nginx-controller LoadBalancer 10.43.237.255 10.62.94.246 80:30312/TCP,443:30366/TCP,9000:31460/TCP 71m
[...]
```
## Stick the nginx-ingress controler and my-nginx app together <a name="stick-nginx-ingress-and-tcp-service"></a>
Finally, the nginx-ingress controller needs a port-mapping pointing to the my-nginx app. This will be done with the config-map `tcp-services-config-map.yml`, referenced earlier in the nginx-ingress deployment definition:
``` ```
--- ---
apiVersion: v1 apiVersion: v1
@ -172,17 +190,9 @@ Apply with `kubectl apply -f tcp-services-config-map.yml`:
``` ```
configmap/tcp-services created configmap/tcp-services created
``` ```
Subsequently the config-map can be edited with `kubectl edit configmap tcp-services -n ingress-nginx`
## Test exposed app on TCP-port 9000 <a name="test-nginx-ingress-and-tcp-service"></a>
Verify nginx-ingress is listening on port 9000 with `kubectl get all --all-namespaces`:
```
[...]
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
[...]
ingress-nginx service/ingress-nginx-controller LoadBalancer 10.43.237.255 10.62.94.246 80:30312/TCP,443:30366/TCP,9000:31460/TCP 71m
[...]
```
Test:
``` ```
dominik@muggler:~$ curl -s http://10.62.94.246:9000 dominik@muggler:~$ curl -s http://10.62.94.246:9000
<html> <html>