# k8s This folder holds all the services required for my private infrastructure. Following contraints apply: * Order of implementation is top down. * Every namespace has a subfolder within this subdirectory. * helm3 # Operations Cleanup `Error` pods. ```sh kubectl get pods | grep Error | cut -d' ' -f 1 | xargs kubectl delete pod ``` Redeploy a deployment: ```sh DEPLOYMENT="rstudio" NAMESPACE="datalab" kubectl patch deployment $DEPLOYMENT -n $NAMESPACE -p "{\"spec\": {\"template\": {\"metadata\": { \"labels\": { \"redeploy\": \"$( date +%s )\"}}}}}" ``` # Deployment ## namespaces DEPRECATED. Namespaces shall be created for the specific service. ```sh namespaces="flux cert-manager nginx-ingress infrapuzzle kuard auth nextcloud datalab web development tt-rss backup monitoring nextcloud mailu" for i in $( echo $NAMESPACES ) ; do k create ns $i done ``` ## helm repositories DEPRECATED. Helm repo will be listed for the individual apps. ```sh helm repo add stable https://kubernetes-charts.storage.googleapis.com helm repo add bitnami https://charts.bitnami.com/bitnami helm repo add k8s-land https://charts.k8s.land helm repo add mailu https://mailu.github.io/helm-charts/ helm repo update ``` ## [ingress-controller](https://github.com/helm/charts/tree/master/stable/nginx-ingress) Apply with helm: ```bash helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo update helm upgrade --install --create-namespace ingress-nginx ingress-nginx/ingress-nginx -n ingress-nginx -f ingress-nginx/ingress-nginx.yaml ``` ## [cert-manager](https://cert-manager.io/docs/tutorials/acme/ingress/) Apply with helm. [See chart.](https://github.com/jetstack/cert-manager): ```bash helm repo add jetstack https://charts.jetstack.io helm repo update helm upgrade --install --create-namespace cert-manager jetstack/cert-manager -n cert-manager -f cert-manager/cert-manager.yaml # this is required: kubectl apply -f cert-manager/staging-issuer.yaml kubectl apply -f cert-manager/production-issuer.yaml ``` To test all this you may use the kuaard demo project: ```sh $ kubectl apply -f kuard # checkout: https://kuard.haumdaucher.de $ kubectl delete -f kuard ``` ## openebs Update with the follwoing command. Chart can be found [here](https://github.com/openebs/charts/tree/master/charts/openebs). ```sh helm repo add openebs https://openebs.github.io/charts helm repo update helm upgrade --install -f openebs/openebs.yml openebs --namespace openebs openebs/openebs ``` ## minio See [chart on GitHub](https://github.com/minio/charts/tree/master/minio). ```sh helm repo add minio https://helm.min.io/ helm repo update helm upgrade --install -f minio/minio.secret.yaml --namespace minio --create-namespace minio minio/minio # # helm delete minio -n minio kubectl delete ns minio ``` ## velero Backup tool. See chart [README](https://github.com/vmware-tanzu/helm-charts/blob/main/charts/velero/README.md). ```sh helm repo add vmware-tanzu https://vmware-tanzu.github.io/helm-charts helm repo update helm upgrade --install --create-namespace --namespace velero -f ./velero/velero.secret.yaml velero vmware-tanzu/velero # # helm delete velero -n velero kubectl delete ns velero ``` A backup may be created using: ```sh velero backup create full-backup --default-volumes-to-restic --include-namespaces datalab,development,nextcloud,tt-rss,zebrium --wait ``` ## Add private docker registry ```sh # create secret base64 encoded and put it in htpasswd helm chart USER='moritz' PASSWORD='xxx' docker run --entrypoint htpasswd --rm registry:2 -Bbn $USER $PASSWORD # # helm upgrade --install docker-registry stable/docker-registry -n development -f development/registry.secret.yaml ##kubectl apply -f development/registry.secret.yaml ``` ### creating docker-pull-secret Create credentials secret [according to docu](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-secret-by-providing-credentials-on-the-command-line): ```sh namespaces="datalab" for i in $( echo $namespaces ) ; do kubectl create secret docker-registry registry-haumdaucher-de \ -n $i \ --docker-server=registry.haumdaucher.de \ --docker-username=moritz \ --docker-password='xxx' \ --docker-email=moritz@moritzgraf.de \ --dry-run -o yaml > ./${i}/docker-pull.yaml.secret done # apply for i in $( echo $namespaces ) ; do kubectl apply -f ${i}/docker-pull.yaml.secret done ``` ## networking with calico Install calicoctl in cluster ```sh kubectl apply -n kube-system -f https://docs.projectcalico.org/manifests/calicoctl.yaml ``` Then you may send commands like: ```sh kubectl exec -ti -n kube-system calicoctl -- /calicoctl get workloadendpoints -n mailu ``` Or on the server directly: ```sh sudo -E /usr/local/bin/calicoctl node checksystem ``` ### metrics See this [documentation](https://docs.projectcalico.org/maintenance/monitor-component-metrics). ```sh kubectl exec -ti -n kube-system calicoctl -- /calicoctl patch felixConfiguration default --patch '{"spec":{"prometheusMetricsEnabled": true}}' kubectl apply -n kube-system -f - <