This repository has been archived on 2023-04-02. You can view files and clone it, but cannot push or open issues or pull requests.
gitops-tbrnt/README.md

140 lines
3.2 KiB
Markdown
Raw Permalink Normal View History

2020-01-25 19:01:21 +00:00
# GitOps for tbrnt k3s hosting
2020-05-04 18:49:36 +00:00
[![Build Status](https://drone.tbrnt.ch/api/badges/tobru/gitops-tbrnt/status.svg)](https://drone.tbrnt.ch/tobru/gitops-tbrnt)
2020-01-26 18:57:32 +00:00
## Repo structure
* Each subdirectory is a namespace
* `_apps` is the meta directory for Argo CD apps
* Another private repo contains stuff in a more
approachable format, f.e. for dealing with
updating sealed-secrets: `gitops-tbrnt-private`
2020-05-04 19:23:44 +00:00
* `_tests` contains some Open Policy Agent rego
files which are used in the Drone CI pipeline
to validate configuration.
2020-01-25 19:01:21 +00:00
2020-01-28 20:15:57 +00:00
## Usage
### Argo CD
#### Access
Either
`sudo -E kubefwd svc -n argocd` and then https://argocd-server/
or
`kubectl port-forward svc/argocd-server -n argocd 8080:443` and
then https://localhost:8080/
#### CLI
* `argocd login argocd-server`
* `argocd app list`
* `argocd app sync <name>`
### Kubeseal (Sealed Secrets)
2020-02-08 14:24:09 +00:00
See README of apps. Basically:
```
kubeseal --controller-namespace sealed-secrets -o yaml -n MYNS < ../../gitops-tbrnt-private/MYNS/MYSECRET.yaml > MYSECRET-secret.yaml
```
2020-01-28 20:15:57 +00:00
## Bootstrap GitOps
After installing k3s, do:
```
2020-02-08 21:07:16 +00:00
# install Argo CD
kubectl create ns argocd
2020-01-28 20:15:57 +00:00
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
2020-02-08 21:07:16 +00:00
kubectl get pods -n argocd -l app.kubernetes.io/name=argocd-server -o name | cut -d'/' -f 2
argocd login argocd-server
# Restore Sealed Secrets secret key
kubectl create ns sealed-secrets
kubectl apply -f ../gitops-tbrnt-private/sealed-secrets/master-key.yaml
# Instantiate Argo Root App
kubectl apply -f _apps/apps.yaml
# Let Argo CD do it's job
argocd app sync apps
argocd app sync sealed-secrets
argocd app sync -l app.kubernetes.io/instance=apps
2020-01-28 20:15:57 +00:00
```
TODO:
2020-02-08 21:07:16 +00:00
* Restore PVCs via K8up
2020-01-28 20:15:57 +00:00
2020-01-25 19:01:21 +00:00
## k3s on Alpine
2020-02-10 20:30:46 +00:00
### Installing: Alpine
Basically follow the [Alpine wiki](https://wiki.alpinelinux.org/wiki/Installation).
Then install prerequisites and some essential packages:
2020-01-28 20:15:57 +00:00
2020-01-26 18:57:32 +00:00
```
2020-02-08 21:07:16 +00:00
apk add \
2020-02-10 20:30:46 +00:00
vim \
2020-02-08 21:07:16 +00:00
iptables \
wireguard-virt \
bash \
curl
```
2020-01-25 19:01:21 +00:00
2020-02-10 20:30:46 +00:00
Needs `community` repo enabled in `/etc/apk/repositories`.
2020-03-21 15:32:57 +00:00
Tweak Sysctl in `/etc/sysctl.conf`:
```
fs.inotify.max_user_instances = 8192
fs.inotify.max_user_watches = 524288
```
2021-08-24 18:09:26 +00:00
Add `rshared` mount option to root filesystem for node-exporter to work correctly.
2020-02-10 20:30:46 +00:00
### Installing: k3s
2020-02-08 21:38:37 +00:00
Via [k3sup](https://github.com/alexellis/k3sup):
2020-01-25 19:01:21 +00:00
2020-02-08 21:07:16 +00:00
```
k3sup install \
--ip=185.95.218.11 \
--user=root \
--local-path=~/.kube/config_knurrli2 \
--sudo=false \
--k3s-extra-args='--tls-san knurrli.tobrunet.ch --cluster-cidr 10.44.0.0/16 --flannel-backend wireguard'
2020-01-25 19:01:21 +00:00
```
2020-02-08 21:38:37 +00:00
### Helpful infos
*Paths*
* Volumes: `/var/lib/rancher/k3s/storage/`
* Config: `/etc/rancher/k3s/`
2020-02-08 22:01:43 +00:00
* Manifests: `/var/lib/rancher/k3s/server/manifests/`
2020-01-25 19:01:21 +00:00
2020-02-08 21:38:37 +00:00
*Links*
2020-01-25 19:01:21 +00:00
* https://rancher.com/docs/k3s/latest/en/advanced/#additional-preparation-for-alpine-linux-setup
* https://github.com/rancher/k3s/issues/660
2020-02-07 20:36:38 +00:00
## Configure Wireguard
`/etc/network/interfaces`
```
auto wg0
iface wg0 inet static
address 10.42.42.16
netmask 255.255.255.0
pre-up ip link add dev wg0 type wireguard
pre-up wg setconf wg0 /etc/wireguard/wg0.conf
post-up ip route add 10.42.42.0/24 dev wg0
post-down ip link delete dev wg0
```
* https://wiki.alpinelinux.org/wiki/Configure_a_Wireguard_interface_(wg)