Kubernetes.K3s.installLog/README.md

312 lines
12 KiB
Markdown
Raw Normal View History

2022-01-09 20:12:30 +00:00
*TODO: Files with sensitive data; migrate to SealedSecret*
```
2022-01-09 20:12:30 +00:00
# line ??: services/TfState/deploy-TfState.yml
# line ??: services/Mastodon/deploy-Mastodon.yml
# line ??: services/PVR/deploy-SpotWeb.yml
```
# Kubernetes.K3s.installLog
*3 VM's provisioned with Ubuntu Server 18.04*
2020-12-15 18:54:02 +00:00
<details><summary>additional lvm configuration</summary>
2021-01-13 11:38:38 +00:00
```shell
2020-12-15 18:54:02 +00:00
pvdisplay
pvcreate /dev/sdb
vgdisplay
vgcreate longhorn-vg /dev/sdb
lvdisplay
lvcreate -l 100%FREE -n longhorn-lv longhorn-vg
ls /dev/mapper
mkfs.ext4 /dev/mapper/longhorn--vg-longhorn--lv
#! add "UUID=<uuid> /mnt/blockstorage ext4 defaults 0 0" to /etc/fstab
mkdir /mnt/blockstorage
mount -a
```
</details>
2021-06-14 14:42:22 +00:00
## K3s cluster
On first node:
2021-01-13 11:38:38 +00:00
```shell
2020-12-08 07:54:12 +00:00
curl -sfL https://get.k3s.io | sh -s - --disable local-path,traefik
cat /var/lib/rancher/k3s/server/token
kubectl config view --raw
```
On subsequent nodes:
2021-01-13 11:38:38 +00:00
```shell
curl -sfL https://get.k3s.io | K3S_URL=https://<fqdn or ip>:6443 K3S_TOKEN=<value from master> sh -
```
2020-11-15 16:19:26 +00:00
### 0) Configure automatic updates
Install Rancher's [System Upgrade Controller](https://rancher.com/docs/k3s/latest/en/upgrades/automated/):
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f https://github.com/rancher/system-upgrade-controller/releases/download/v0.6.2/system-upgrade-controller.yaml
```
Apply a [server (master node)](https://code.spamasaurus.com/djpbessems/Kubernetes.K3s.installLog/src/branch/master/system/UpgradeController/plan-Server.yml) and [agent (worker node)](https://code.spamasaurus.com/djpbessems/Kubernetes.K3s.installLog/src/branch/master/system/UpgradeController/plan-Agent.yml) plan:
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f system/UpgradeController/plan-Server.yml -f system/UpgradeController/plan-Agent.yml
```
### 1) Persistent storage
2020-09-23 13:50:31 +00:00
#### 1.1) `storageClass` for SMB (CIFS):
2020-09-23 13:35:17 +00:00
See https://github.com/kubernetes-csi/csi-driver-smb:
2021-01-13 11:38:38 +00:00
```shell
2020-09-23 13:35:17 +00:00
curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/master/deploy/install-driver.sh | bash -s master --
```
2020-11-10 16:37:52 +00:00
Store credentials in `secret`:
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl create secret generic smb-credentials --from-literal username=<<omitted>> --from-literal domain=<<omitted>> --from-literal password=<<omitted>>
```
2020-09-23 13:35:17 +00:00
2020-09-23 13:50:31 +00:00
#### 1.2) `flexVolume` for SMB (CIFS):
2021-01-13 11:38:38 +00:00
```shell
curl -Ls https://github.com/juliohm1978/kubernetes-cifs-volumedriver/blob/master/install.yaml -o storage/flexVolSMB/daemonSet-flexVolSMB.yml
```
Override drivername to something more sensible (see [storage/flexVolSMB/daemonSet-flexVolSMB.yml](https://code.spamasaurus.com/djpbessems/Kubernetes.K3s.installLog/src/branch/master/storage/flexVolSMB/daemonSet-flexVolSMB.yml))
2021-01-13 11:38:38 +00:00
```yaml
spec:
template:
spec:
containers:
- image: juliohm/kubernetes-cifs-volumedriver-installer:2.0
...
env:
- name: VENDOR
value: mount
- name: DRIVER
value: smb
...
```
Perform installation:
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f storage/flexVolSMB/daemonSet-flexVolSMB.yml
```
Wait for installation to complete (check logs of all installer-pods), then delete `daemonSet`:
2021-01-13 11:38:38 +00:00
```shell
kubectl delete -f storage/flexVolSMB/daemonSet-flexVolSMB.yml
```
Store credentials in `secret`:
2021-01-13 11:38:38 +00:00
```shell
kubectl create secret generic --type=mount/smb smb-secret --from-literal=username=<<omitted>> --from-literal=password=<<omitted>>
```
2020-09-23 13:50:31 +00:00
#### 1.3) `storageClass` for distributed block storage:
See [Longhorn Helm Chart](https://longhorn.io/):
2021-01-13 11:38:38 +00:00
```shell
kubectl create namespace longhorn-system
helm repo add longhorn https://charts.longhorn.io
helm install longhorn longhorn/longhorn --namespace longhorn-system --values=storage/Longhorn/chart-values.yml
```
Expose Longhorn's dashboard through `IngressRoute`:
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f storage/Longhorn/ingressRoute-Longhorn.yml
```
2021-06-14 14:42:22 +00:00
Add additional `storageClass` with backup schedule:
***After** specifying a NFS backup target (syntax: `nfs://servername:/path/to/share`) through Longhorn's dashboard*
2021-01-13 11:38:38 +00:00
```yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: longhorn-dailybackup
provisioner: driver.longhorn.io
allowVolumeExpansion: true
parameters:
numberOfReplicas: "3"
staleReplicaTimeout: "2880"
fromBackup: ""
recurringJobs: '[{"name":"backup", "task":"backup", "cron":"0 0 * * *", "retain":14}]'
```
Then make this the new default `storageClass`:
2021-01-13 11:38:38 +00:00
```shell
kubectl patch storageclass longhorn-dailybackup -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
#kubectl delete storageclass longhorn
```
### 2) Ingress Controller
##### 2.1) Create `configMap`, `secret` and `persistentVolumeClaim`
The `configMap` contains Traefik's static and dynamic config:
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl apply -f ingress/Traefik2.x/configMap-Traefik.yml
```
The `secret` contains credentials for Cloudflare's API:
2021-01-13 11:38:38 +00:00
```shell
kubectl create secret generic traefik-cloudflare --from-literal=CF_API_EMAIL=<<omitted>> --from-literal=CF_API_KEY=<<omitted>> --namespace kube-system
```
The `persistentVolumeClaim` will contain `/data/acme.json` (referenced as `existingClaim`):
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl apply -f ingress/Traefik2.x/persistentVolumeClaim-Traefik.yml
```
##### 2.2) Install Helm Chart
See [Traefik 2.x Helm Chart](https://github.com/containous/traefik-helm-chart):
2021-01-13 11:38:38 +00:00
```shell
helm repo add traefik https://containous.github.io/traefik-helm-chart
helm repo update
helm install traefik traefik/traefik --namespace kube-system --values=ingress/Traefik2.x/chart-values.yml
```
##### 2.3) Replace `IngressRoute` for Traefik's dashboard:
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f ingress/Traefik2.x/ingressRoute-Traefik.yaml
kubectl delete ingressroute traefik-dashboard --namespace kube-system
```
### 3) Secret management
*Prereq*: latest `kubeseal` [release](https://github.com/bitnami-labs/sealed-secrets/releases)
##### 3.1) Install Helm Chart
See [Bitnami Sealed Secrets](https://github.com/bitnami-labs/sealed-secrets#helm-chart):
2021-01-13 11:38:38 +00:00
```shell
helm repo add sealed-secrets https://bitnami-labs.github.io/sealed-secrets
helm repo update
helm install sealed-secrets-controller -n kube-system sealed-secrets/sealed-secrets
```
2022-01-09 19:40:13 +00:00
Fix servicename (remove `name: http` - see [#502](https://github.com/bitnami-labs/sealed-secrets/issues/502)):
```
2022-01-09 19:40:13 +00:00
kubectl edit service -n kube-system sealed-secrets-controller
```
### 4) Services
##### 4.1) [Adminer](https://www.adminer.org/) <small>(SQL management)</small>
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl apply -f services/Adminer/configMap-Adminer.yml
kubectl apply -f services/Adminer/deploy-Adminer.yml
2022-01-09 19:57:16 +00:00
kubectl apply -f services/Adminer/sealedSecret-Adminer.yml
```
2021-06-14 14:42:22 +00:00
##### 4.2) [Vaultwarden](https://github.com/dani-garcia/vaultwarden) <small>(password manager)</small>
*Requires [mount.cifs](https://linux.die.net/man/8/mount.cifs)' option `nobrl`*
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl apply -f services/Bitwarden/deploy-Bitwarden.yml
2022-01-09 19:57:16 +00:00
kubectl apply -f services/Bitwarden/sealedSecret-Bitwarden.yml
```
2022-01-09 20:12:30 +00:00
##### 4.3) [DDclient](https://github.com/linuxserver/docker-ddclient) <small>(dynamic dns)</small>
```shell
kubectl apply -f services/DDclient/deploy-DDclient.yml
kubectl apply -f services/DDclient/sealedSecret-DDclient.yml
```
##### 4.4) [DroneCI](https://drone.io/) <small>(contineous delivery)</small>
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl apply -f services/DroneCI/deploy-DroneCI.yml
2022-01-09 19:57:16 +00:00
kubectl apply -f services/DroneCI/sealedSecret-DroneCI.yml
```
2022-01-09 20:12:30 +00:00
##### 4.5) [Gitea](https://gitea.io/) <small>(git repository)</small>
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl apply -f services/Gitea/deploy-Gitea.yml
```
2022-01-09 20:12:30 +00:00
##### 4.6) [Gotify](https://gotify.net/) <small>(notifications)</small>
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl apply -f services/Gotify/deploy-Gotify.yml
```
2022-01-09 20:12:30 +00:00
##### 4.7) [Guacamole](https://guacamole.apache.org/doc/gug/guacamole-docker.html) <small>(remote desktop gateway)</small>
*Requires specifying a `uid` & `gid` in both the `securityContext` of the MySQL container and the `persistentVolume`*
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl apply -f services/Guacamole/deploy-Guacamole.yml
2022-01-09 20:12:30 +00:00
kubectl apply -f services/Guacamole/sealedSecret-Guacamole.yml
```
Wait for the included containers to start, then perform the following commands to initialize the database:
2021-01-13 11:38:38 +00:00
```shell
kubectl exec -i guacamole-<pod-id> --container guacamole -- /opt/guacamole/bin/initdb.sh --mysql > initdb.sql
kubectl exec -i guacamole-<pod-id> --container mysql -- mysql -uguacamole -pguacamole guacamole < initdb.sql
kubectl rollout restart deployment guacamole
```
2022-01-09 20:12:30 +00:00
##### 4.8) [Lighttpd](https://www.lighttpd.net/) <small>(webserver)</small>
2021-06-14 14:42:22 +00:00
*Serves various semi-containerized websites; respective webcontent is stored on fileshare*
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl apply -f services/Lighttpd/configMap-Lighttpd.yml
kubectl apply -f services/Lighttpd/deploy-Lighttpd.yml
kubectl apply -f services/Lighttpd/cronJob-Spotweb.yml
```
2022-01-09 20:12:30 +00:00
##### 4.9) PVR `namespace` <small>(automated media management)</small>
*Containers use shared resources to be able to interact with downloaded files*
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl create secret generic --type=mount/smb smb-secret --from-literal=username=<<omitted>> --from-literal=password=<<omitted>> -n pvr
kubectl apply -f services/PVR/persistentVolumeClaim-PVR.yml
kubectl apply -f services/PVR/storageClass-PVR.yml
```
2022-01-09 20:12:30 +00:00
###### 4.9.1) [Overseerr](https://overseerr.dev/) <small>(request management)</small>
2021-06-14 14:42:22 +00:00
```shell
kubectl apply -f services/PVR/deploy-Overseerr.yml
```
2022-01-09 20:12:30 +00:00
###### 4.9.2) [Plex](https://www.plex.tv/) <small>(media library)</small>
*Due to usage of symlinks, partially incompatible with SMB-share-backed storage*
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f services/PVR/deploy-Plex.yml
```
2020-11-21 14:59:09 +00:00
After deploying, Plex server needs to be *claimed* (=assigned to Plex-account):
2021-01-13 11:38:38 +00:00
```shell
2020-11-21 14:59:09 +00:00
kubectl get endpoints Plex -n PVR
```
Browse to the respective IP address (http://<nodeipaddress>:32400/web) and follow instructions.
2022-01-09 20:12:30 +00:00
###### 4.9.3) [Prowlarr](https://github.com/Prowlarr/Prowlarr) <small>(indexer management)</small>
```shell
kubectl apply -f services/PVR/deploy-Prowlarr.yml
```
###### 4.9.4) [Radarr](https://radarr.video/) <small>(movie management)</small>
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f services/PVR/deploy-Radarr.yml
```
2022-01-09 20:12:30 +00:00
###### 4.9.5) [Readarr](https://readarr.com/) <small>(book management)</small>
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f services/PVR/deploy-Readarr.yml
```
2022-01-09 20:12:30 +00:00
###### 4.9.6) [SABnzbd](https://sabnzbd.org/) <small>(download client)</small>
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f services/PVR/deploy-SABnzbd.yml
```
2022-01-09 20:12:30 +00:00
###### 4.9.7) [Sonarr](https://sonarr.tv/) <small>(tv management)</small>
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f services/PVR/deploy-Sonarr.yml
```
2022-01-09 20:12:30 +00:00
##### 4.10) [Shaarli](https://github.com/shaarli/Shaarli) <small>(bookmarks/notes)</small>
2021-01-13 11:38:38 +00:00
```shell
2020-11-10 16:37:52 +00:00
kubectl apply -f services/Shaarli/deploy-Shaarli.yml
```
2021-06-14 14:42:22 +00:00
##### 4.11) [Traefik-Certs-Dumper](https://github.com/ldez/traefik-certs-dumper) <small>(certificate tooling)</small>
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f services/TraefikCertsDumper/deploy-TraefikCertsDumper.yml
```
2021-06-14 14:42:22 +00:00
##### 4.12) [Unifi-Controller]() <small>(wlan AP management)</small>
2021-01-13 11:38:38 +00:00
```shell
kubectl apply -f services/Unifi/deploy-Unifi.yml
```
*Change STUN port to non-default:*
2021-01-13 11:38:38 +00:00
```shell
kubectl exec --namespace unifi -it unifi-<uuid> -- /bin/bash
sed -e 's/# unifi.stun.port=3478/unifi.stun.port=3479/' -i /data/system.properties
exit
kubectl rollout restart deployment --namespace unifi unifi
```
*Update STUN url on devices:* <small>doesn't seem to work</small>
2021-01-13 11:38:38 +00:00
```shell
ssh <username>@<ipaddress>
sed -e 's|stun://<ipaddress>|stun://<ipaddress>:3479|' -i /etc/persistent/cfg/mgmt
```
### 5) Miscellaneous
2021-06-14 14:42:22 +00:00
*Various notes/useful links*
* Replacement for [not-yet-deprecated](https://github.com/kubernetes/kubectl/issues/151) `kubectl get all -A`:
2021-06-14 14:42:22 +00:00
kubectl get $(kubectl api-resources --verbs=list -o name | paste -sd, -) --ignore-not-found --all-namespaces
* `DaemonSet` to configure nodes' **sysctl** `fs.inotify.max-user-watches`:
2021-06-14 14:42:22 +00:00
kubectl apply -f system/InotifyMaxWatchers/daemonSet-InotifyMaxWatchers.yml
* Debug DNS lookups within the cluster:
2021-06-14 14:42:22 +00:00
kubectl run -it --rm dnsutils --restart=Never --image=gcr.io/kubernetes-e2e-test-images/dnsutils -- nslookup [-debug] [fqdn]
or
2021-06-14 14:42:22 +00:00
kubectl run -it --rm busybox --restart=Never --image=busybox:1.28 -- nslookup api.github.com [-debug] [fqdn]
* Delete namespaces stuck in `Terminating` state:
2021-06-14 14:42:22 +00:00
kubectl get namespace <name> -o json | jq -j '.spec.finalizers=null' > tmp.json
kubectl replace --raw "/api/v1/namespaces/<name>/finalize" -f ./tmp.json
rm ./tmp.json