# 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 (non persistent stuff) ## [ingress-nginx](https://github.com/kubernetes/ingress-nginx/tree/master/charts/ingress-nginx) 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 # apply the two issuer classes 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). Pitfall: * On fresh installation: activate *ndmOperator*, so that CRDs are correctly installed. It may be deactivated afterwards. ```sh helm repo add openebs https://openebs.github.io/charts helm repo update helm upgrade --install --create-namespace -f openebs/openebs.yml openebs --namespace openebs openebs/openebs k apply -f openebs/storageclass.yml ``` ## minio (bitnami) Switching to [Bitnami chart](https://artifacthub.io/packages/helm/bitnami/minio) as "normal" chart just too big. ```sh helm repo update helm upgrade --install -f minio/minio.secret.yaml --namespace minio --create-namespace minio bitnami/minio ``` ## minio **DEPRECATED - INSTALL WITH OPERATOR** See [chart on GitHub](https://github.com/minio/charts/tree/master/minio). ```sh helm repo add minio https://charts.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 kubectl create secret generic rclone-config --from-file=./velero/rclone.secret kubectl apply -f velero/dropbox_sync.yml # # helm delete velero -n velero kubectl delete ns velero ``` A manual backup may be created executing the following command. **Note: Keep backuped namespaces in sync with config from helm chart!!!** ```sh DATE=$( date +%Y%m%d ) velero backup create $DATE --include-namespaces datalab,development,nextcloud,tt-rss,zebrium,mailu --wait ``` ## Add private docker registry **TODO: chart no longer exists. Check how to replace this someday.** ```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 --create-namespace 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 moritz web" # the following is ONLY required to update the secret file!! 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 (may be executed as needed) for i in $( echo $namespaces ) ; do kubectl apply -f datalab/docker-pull.yaml.secret -n $i done ``` For kubeflow: ```sh cat << EOF >> config.json { "auths": { "https://index.docker.io/v1/": { "auth": "$( echo -n 'moritz:password' | base64 )" } } } EOF kubectl create -n kubeflow configmap docker-config --from-file=config.json rm config.json ``` ## 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 - <