2020-09-01 17:44:43 +02:00
# Kubernetes.K3s.installLog
2023-12-28 10:03:36 +11:00
*3 VM's provisioned with Ubuntu Server 22.04*
2020-12-15 19:54:02 +01:00
< details > < summary > additional lvm configuration< / summary >
2021-01-13 12:38:38 +01:00
```shell
2020-12-15 19:54:02 +01:00
pvdisplay
pvcreate /dev/sdb
vgdisplay
vgcreate longhorn-vg /dev/sdb
lvdisplay
lvcreate -l 100%FREE -n longhorn-lv longhorn-vg
ls /dev/mapper
2022-04-06 11:52:59 +02:00
mkfs.ext4 /dev/mapper/longhorn--vg-longhorn--lv
#! add "UUID=<uuid> /mnt/blockstorage ext4 defaults 0 0" to /etc/fstab
2020-12-15 19:54:02 +01:00
mkdir /mnt/blockstorage
mount -a
```
< / details >
2020-09-01 17:44:43 +02:00
2021-06-14 16:42:22 +02:00
## K3s cluster
2022-04-01 21:48:02 +02:00
On first node (replace `<floating ip>` with the correct value):
2021-01-13 12:38:38 +01:00
```shell
2024-01-16 20:42:27 +11:00
curl -sfL https://get.k3s.io | sh -s - server --cluster-init --disable local-storage,servicelb --tls-san < floating ip >
2020-09-01 17:44:43 +02:00
cat /var/lib/rancher/k3s/server/token
kubectl config view --raw
```
2022-04-01 21:48:02 +02:00
Install kube-vip (replace `<interface name>` and `<floating ip>` with the correct values):
2021-01-13 12:38:38 +01:00
```shell
2022-04-01 21:48:02 +02:00
ctr image pull ghcr.io/kube-vip/kube-vip:latest
cat < < EOF > /var/lib/rancher/k3s/server/manifests/kube-vip.yml
$(curl https://kube-vip.io/manifests/rbac.yaml)
---
$(ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:latest vip /kube-vip manifest daemonset --interface < interface name > --address < floating ip > --inCluster --taint --controlplane --services --arp --leaderElection)
EOF
```
2022-04-05 18:06:19 +02:00
On subsequent nodes (replace `<floating ip>` and `<value from master>` with the correct values):
2022-04-01 21:48:02 +02:00
```shell
2024-01-16 20:42:27 +11:00
curl -sfL https://get.k3s.io | K3S_URL=https://< floating ip > :6443 K3S_TOKEN=< value from master > sh -s - server --disable local-storage,servicelb
2020-09-01 17:44:43 +02:00
```
2020-11-15 17:19:26 +01:00
### 0) Configure automatic updates
2020-09-01 17:44:43 +02:00
Install Rancher's [System Upgrade Controller ](https://rancher.com/docs/k3s/latest/en/upgrades/automated/ ):
2021-01-13 12:38:38 +01:00
```shell
2022-03-14 09:56:36 +01:00
kubectl apply -f https://github.com/rancher/system-upgrade-controller/releases/latest/download/system-upgrade-controller.yaml
2020-09-01 17:44:43 +02:00
```
2022-04-05 18:06:19 +02:00
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 12:38:38 +01:00
```shell
2022-04-05 18:06:19 +02:00
kubectl apply -f system/UpgradeController/plan-Server.yml # -f system/UpgradeController/plan-Agent.yml
2020-09-01 17:44:43 +02:00
```
2022-04-06 11:41:29 +02:00
### 1) Secret management
*Prereq*: latest `kubeseal` [release ](https://github.com/bitnami-labs/sealed-secrets/releases )
##### 1.1) Install Helm Chart
See [Bitnami Sealed Secrets ](https://github.com/bitnami-labs/sealed-secrets#helm-chart ):
```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
```
Retrieve public/private keys (*store these on a **secure** location!*):
```shell
kubectl get secret -n kube-system -l sealedsecrets.bitnami.com/sealed-secrets-key -o yaml > BitnamiSealedSecrets.masterkey.yml
```
2020-09-01 17:44:43 +02:00
2022-04-06 11:41:29 +02:00
### 2) Persistent storage
#### 2.1) `storageClass` for SMB (CIFS):
2020-09-23 15:35:17 +02:00
See https://github.com/kubernetes-csi/csi-driver-smb:
2021-01-13 12:38:38 +01:00
```shell
2020-09-23 15:35:17 +02:00
curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/master/deploy/install-driver.sh | bash -s master --
```
2020-11-10 17:37:52 +01:00
Store credentials in `secret` :
2021-01-13 12:38:38 +01:00
```shell
2022-04-06 11:41:29 +02:00
kubectl apply -f storage/csi-driver-smb/sealedSecret-CSIdriverSMB.yml
2020-11-10 17:37:52 +01:00
```
2020-09-23 15:35:17 +02:00
2022-04-06 11:41:29 +02:00
#### 2.2) `flexVolume` for SMB (CIFS):
2021-01-13 12:38:38 +01:00
```shell
2020-09-01 17:44:43 +02:00
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 12:38:38 +01:00
```yaml
2020-09-01 17:44:43 +02:00
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 12:38:38 +01:00
```shell
2020-09-01 17:44:43 +02:00
kubectl apply -f storage/flexVolSMB/daemonSet-flexVolSMB.yml
```
2024-01-16 20:42:27 +11:00
Wait for installation to complete (check logs of all installer-pods), then pause `daemonSet` :
2021-01-13 12:38:38 +01:00
```shell
2024-01-16 20:42:27 +11:00
kubectl patch daemonset juliohm-cifs-volumedriver-installer -p '{"spec": {"template": {"spec": {"nodeSelector": {"intentionally-paused": ""}}}}}'
2020-09-01 17:44:43 +02:00
```
Store credentials in `secret` :
2021-01-13 12:38:38 +01:00
```shell
2022-04-06 11:41:29 +02:00
kubectl apply -f storage/flexVolSMB/sealedSecret-flexVolSMB.yml
2020-09-01 17:44:43 +02:00
```
2020-09-23 15:50:31 +02:00
2022-04-06 11:41:29 +02:00
#### 2.3) `storageClass` for distributed block storage:
2020-11-14 23:57:19 +01:00
See [Longhorn Helm Chart ](https://longhorn.io/ ):
2021-01-13 12:38:38 +01:00
```shell
2023-12-28 10:03:36 +11:00
helm repo add longhorn https://charts.longhorn.io & & helm repo update
helm install longhorn longhorn/longhorn --namespace longhorn-system --create-namespace --values=storage/Longhorn/chart-values.yml
2020-11-14 23:57:19 +01:00
```
2023-12-28 10:03:36 +11:00
2022-02-03 15:33:49 +01:00
Log on to the web interface and delete the default disks on each node (mounted at `/var/lib/longhorn` ) and replace them with new disks mounted at `/mnt/blockstorage` .
2020-09-01 17:44:43 +02:00
2022-04-06 11:41:29 +02:00
### 3) Ingress Controller
2023-12-28 10:03:36 +11:00
Reconfigure default Traefik configuration:
See [Traefik 2.x Helm Chart ](https://github.com/traefik/traefik-helm-chart ) and [HelmChartConfig ](https://docs.k3s.io/helm )
2021-01-13 12:38:38 +01:00
```shell
2023-12-28 10:03:36 +11:00
kubectl apply -f ingress/Traefik2.x/helmchartconfig-traefik.yaml
2020-09-01 17:44:43 +02:00
```
2022-04-05 18:02:18 +02:00
### 4) GitOps
2024-01-21 10:30:41 +11:00
##### 4.1) Install Helm Chart
2022-04-05 18:02:18 +02:00
See [ArgoCD ](https://argo-cd.readthedocs.io/en/stable/getting_started/#getting-started ):
```shell
2024-01-21 10:30:41 +11:00
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
helm install argo-cd -n argo-cd --create-namespace argo/argo-cd --values system/ArgoCD/chart-values.yml
2022-04-05 18:02:18 +02:00
```
Retrieve initial password:
```shell
2022-04-06 11:52:59 +02:00
kubectl get secret -n argocd argocd-initial-admin-secret -o jsonpath='{.data.password}' | base64 -d; echo
2022-04-05 18:02:18 +02:00
```
Login with username `admin` and the initial password, browse to `User Info` and `Update Password` .
2022-04-06 11:41:29 +02:00
### 5) Services
2024-09-29 13:59:09 +10:00
##### 5.1) [Argus]() <small>(release management)</small>
2021-01-13 12:38:38 +01:00
```shell
2024-09-29 13:59:09 +10:00
kubectl apply -f services/Argus
2020-09-01 17:44:43 +02:00
```
2024-09-29 13:59:09 +10:00
##### 5.2) [Authelia]() <small>(single sign-on))</small>
2021-01-13 12:38:38 +01:00
```shell
2024-09-29 13:59:09 +10:00
kubectl apply -f services/Authelia
2020-09-01 17:44:43 +02:00
```
2024-09-29 13:59:09 +10:00
##### 5.3) [Vaultwarden](https://github.com/dani-garcia/vaultwarden) <small>(password manager)</small>
*Requires [mount.cifs ](https://linux.die.net/man/8/mount.cifs )' option `nobrl` *
2022-01-09 21:12:30 +01:00
```shell
2024-09-29 13:59:09 +10:00
kubectl apply -f services/Vaultwarden
2022-01-09 21:12:30 +01:00
```
2024-09-29 13:59:09 +10:00
##### 5.4) [DDclient](https://github.com/linuxserver/docker-ddclient) <small>(dynamic dns)</small>
2021-01-13 12:38:38 +01:00
```shell
2024-09-29 13:59:09 +10:00
kubectl apply -f services/DDclient
2020-09-01 17:44:43 +02:00
```
2022-04-06 11:41:29 +02:00
##### 5.5) [Gitea](https://gitea.io/) <small>(git repository)</small>
2021-01-13 12:38:38 +01:00
```shell
2024-09-29 13:59:09 +10:00
kubectl apply -f services/Gitea
2020-09-01 17:44:43 +02:00
```
2022-04-06 11:41:29 +02:00
##### 5.6) [Gotify](https://gotify.net/) <small>(notifications)</small>
2021-01-13 12:38:38 +01:00
```shell
2024-09-29 13:59:09 +10:00
kubectl apply -f services/Gotify
2020-09-01 17:44:43 +02:00
```
2022-04-06 11:41:29 +02:00
##### 5.7) [Guacamole](https://guacamole.apache.org/doc/gug/guacamole-docker.html) <small>(remote desktop gateway)</small>
2024-09-29 13:59:09 +10:00
*Requires specifying a `uid` & `gid` in both the `securityContext` of the db container and the `persistentVolume` *
2021-01-13 12:38:38 +01:00
```shell
2024-09-29 13:59:09 +10:00
kubectl apply -f services/Guacamole
2020-09-01 17:44:43 +02:00
```
Wait for the included containers to start, then perform the following commands to initialize the database:
2021-01-13 12:38:38 +01:00
```shell
2024-09-29 13:59:09 +10:00
kubectl exec -n guacamole -i guacamole-< pod-id > --container guacamole -- /opt/guacamole/bin/initdb.sh --postgresql > initdb.sql
kubectl exec -n guacamole -i guacamole-< pod-id > --container db -- psql -Uguacamole -f - < initdb.sql
kubectl rollout restart deployment -n guacamole guacamole
2020-09-01 17:44:43 +02:00
```
2022-04-06 11:41:29 +02:00
##### 5.8) [Lighttpd](https://www.lighttpd.net/) <small>(webserver)</small>
2021-06-14 16:42:22 +02:00
*Serves various semi-containerized websites; respective webcontent is stored on fileshare*
2021-01-13 12:38:38 +01:00
```shell
2020-11-10 17:37:52 +01:00
kubectl apply -f services/Lighttpd/configMap-Lighttpd.yml
kubectl apply -f services/Lighttpd/deploy-Lighttpd.yml
2020-09-01 17:44:43 +02:00
```
2022-04-06 11:41:29 +02:00
##### 5.9) PVR `namespace` <small>(automated media management)</small>
2020-10-16 09:10:23 +02:00
*Containers use shared resources to be able to interact with downloaded files*
2021-01-13 12:38:38 +01:00
```shell
2020-11-10 17:37:52 +01:00
kubectl create secret generic --type=mount/smb smb-secret --from-literal=username=< < omitted > > --from-literal=password=< < omitted > > -n pvr
2020-10-16 09:10:23 +02:00
kubectl apply -f services/PVR/persistentVolumeClaim-PVR.yml
kubectl apply -f services/PVR/storageClass-PVR.yml
```
2024-09-29 13:59:09 +10:00
###### 5.9.1) [Plex](https://www.plex.tv/) <small>(media library)</small>
2020-11-14 23:57:19 +01:00
*Due to usage of symlinks, partially incompatible with SMB-share-backed storage*
2021-01-13 12:38:38 +01:00
```shell
2020-11-14 23:57:19 +01:00
kubectl apply -f services/PVR/deploy-Plex.yml
```
2020-11-21 15:59:09 +01:00
After deploying, Plex server needs to be *claimed* (=assigned to Plex-account):
2021-01-13 12:38:38 +01:00
```shell
2020-11-21 15:59:09 +01:00
kubectl get endpoints Plex -n PVR
```
2022-04-06 11:52:59 +02:00
Browse to the respective IP address (http://< nodeipaddress > :32440/web) and follow instructions.
2024-09-29 13:59:09 +10:00
###### 5.9.2) [Prowlarr](https://github.com/Prowlarr/Prowlarr) <small>(indexer management)</small>
2022-01-09 21:12:30 +01:00
```shell
kubectl apply -f services/PVR/deploy-Prowlarr.yml
```
2024-09-29 13:59:09 +10:00
###### 5.9.3) [Radarr](https://radarr.video/) <small>(movie management)</small>
2021-01-13 12:38:38 +01:00
```shell
2020-10-16 09:10:23 +02:00
kubectl apply -f services/PVR/deploy-Radarr.yml
```
2024-09-29 13:59:09 +10:00
###### 5.9.4) [SABnzbd](https://sabnzbd.org/) <small>(download client)</small>
2021-01-13 12:38:38 +01:00
```shell
2020-10-16 09:10:23 +02:00
kubectl apply -f services/PVR/deploy-SABnzbd.yml
```
2024-09-29 13:59:09 +10:00
###### 5.9.5) [Sonarr](https://sonarr.tv/) <small>(tv management)</small>
2021-01-13 12:38:38 +01:00
```shell
2020-10-16 09:10:23 +02:00
kubectl apply -f services/PVR/deploy-Sonarr.yml
```
2022-04-06 11:41:29 +02:00
### 6) Miscellaneous
2021-06-14 16:42:22 +02:00
*Various notes/useful links*
2020-09-01 17:44:43 +02:00
* Replacement for [not-yet-deprecated ](https://github.com/kubernetes/kubectl/issues/151 ) `kubectl get all -A` :
2021-06-14 16:42:22 +02:00
2020-09-01 17:44:43 +02:00
kubectl get $(kubectl api-resources --verbs=list -o name | paste -sd, -) --ignore-not-found --all-namespaces
2020-11-14 23:57:19 +01:00
* `DaemonSet` to configure nodes' **sysctl** `fs.inotify.max-user-watches` :
2021-06-14 16:42:22 +02:00
2020-11-14 23:57:19 +01:00
kubectl apply -f system/InotifyMaxWatchers/daemonSet-InotifyMaxWatchers.yml
2021-01-05 14:37:30 +01:00
* Debug DNS lookups within the cluster:
2021-06-14 16:42:22 +02:00
2021-01-05 14:37:30 +01:00
kubectl run -it --rm dnsutils --restart=Never --image=gcr.io/kubernetes-e2e-test-images/dnsutils -- nslookup [-debug] [fqdn]
or
2021-06-14 16:42:22 +02:00
2021-01-05 14:37:30 +01:00
kubectl run -it --rm busybox --restart=Never --image=busybox:1.28 -- nslookup api.github.com [-debug] [fqdn]
2022-06-08 09:25:31 +00:00