Kubernetes
Jump to navigation
Jump to search
Cheats and random commands
kubectl describe nodes sudo journalctl -u k3s kubectl scale deployment my-deployment --replicas=0 kubectl scale deployment my-deployment --replicas=3 export IP_HELLO=192.168.0.137 curl --resolve "pi5:80:$IP_HELLO" -i http://pi5 for p in $(kubectl get pods | grep Terminating | awk '{print $1}'); do kubectl delete pod $p --grace-period=0 --force;done ansible-playbook -i inventory/mycluster/inventory.ini --become --become-user=root cluster.yml -v /etc/kubernetes/admin.conf ~/.kube/config
make a storage class default
kubectl patch storageclass nfs-client -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
install k3s
with rights to access it as user
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC='--write-kubeconfig-mode=644' sh - curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="server" sh -s - --flannel-backend none curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="server" sh -s - --token 424242
change interface
https://jaehong21.com/posts/k3s/02-access-outside/
sudo vi /etc/systemd/system/k3s.service
ExecStart=/usr/local/bin/k3s \ server \ '--disable=traefik' \ '--token' \ '12345' \ '--write-kubeconfig-mode=644' \ '–advertise-address=192.168.0.137' \ '-tls-san=192.168.0.137' \
install nginx ingress controller
https://docs.k3s.io/cluster-access
helm upgrade --install ingress-nginx ingress-nginx \ --repo https://kubernetes.github.io/ingress-nginx \ --namespace ingress-nginx --create-namespace
helm upgrade --install ingress-nginx ingress-nginx \ --repo https://kubernetes.github.io/ingress-nginx \ --namespace ingress-nginx --create-namespace \ --set ingressClassResource.default=true \ --set controller.watchIngressWithoutClass=true
patch ingress controller config
kubectl patch cm ingress-nginx-controller -n ingress-nginx -p '{"data":{"annotations-risk-level":"Critical"}}' kubectl patch cm ingress-nginx-controller -n ingress-nginx -p '{"data":{"strict-validate-path-type":"false"}}' kubectl patch cm ingress-nginx-controller -n ingress-nginx -p '{"data":{"enable-snippet-annotations":"true"}}'
install helm
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 chmod 700 get_helm.sh ./get_helm.sh
access k3s cluster via helm
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl get pods --all-namespaces helm ls --all-namespaces
helmfile
mkdir helmfile && cd helmfile wget https://github.com/helmfile/helmfile/releases/download/v1.0.0-rc.12/helmfile_1.0.0-rc.12_linux_amd64.tar.gz tar xvzf helmfile_1.0.0-rc.12_linux_amd64.tar.gz sudo mv helmfile /usr/local/bin helmfile apply -e dev -n opendesk helmfile apply -e dev -n opendesk -l component=collabora
install helm-diff
helm plugin install https://github.com/databus23/helm-diff
remove k3s
/usr/local/bin/k3s-uninstall.sh
show everything in a namespace
kubectl --namespace=gitlab-runner show all
get shell
kubectl exec --stdin --tty shell-demo -- /bin/bash
events
kubectl get events --namespace=gitlab-runner
get all events
kubectl get events --all-namespaces --sort-by='.metadata.creationTimestamp'
create namespace
kubectl create ns gitlab-runner
gitlab-runner
For swep20:
cd ~/kubernetes/gitlab-runner/ helm install --namespace gitlab-runner gitlab-runner-swep20-2 -f values_swep20.yaml gitlab/gitlab-runner helm uninstall gitlab-runner --namespace=gitlab-runner
edit configmap via editor
kubectl edit cm -n kube-system coredns
Recreate/Restart after edit:
kubectl delete pod coredns
fix gitlab-runner for docker in docker
Edit config map and add following before runner start command:
# Add docker volumes cat >> /home/gitlab-runner/.gitlab-runner/config.toml << EOF [[runners.kubernetes.volumes.host_path]] name = "alias-docker-in-docker" mount_path = "/var/run/docker.sock" read_only = true host_path = "/var/run/docker.sock" EOF
add helm charts
helm repo add stable https://charts.helm.sh/stable helm repo add gitlab https://charts.gitlab.io/ helm repo update
cluster info
kubectl cluster-info
delete service and deployment
- https://www.slingacademy.com/article/how-to-completely-remove-a-kubernetes-deployment-with-examples/
kubectl get all kubectl delete svc XY kubectl delete deployment XY kubectl delete pod XY kubectl delete ns XYZ