# K8s Index ## Collection of useful commands and code snippets related to K8s ### Find and delete all pods with regex match **Note:** Change `^name` with pod name Without force ```bash kubectl delete pods $(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep ^name) ``` With force ```bash kubectl delete pods $(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep ^name) --force --grace-period=0 ``` --- ### Create k8s user super with cluster-admin role and fetch its api key ```bash kubectl create sa super ``` ```bash kubectl create clusterrolebinding super-admin-binding --clusterrole=cluster-admin --serviceaccount=default:super ``` ```bash kubectl apply -f - < -it --image=ubuntu .... .... chroot /host ... ... bash # now you have ssh connection of the node ``` ### Run a K8s benchmark ```bash kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job.yaml ``` to see result ```bash kubectl get pods kubectl logs # pods name will be kube-bench-***** ``` ### add docker Registry secret ```bash kubectl create secret docker-registry -n \ --docker-server= \ --docker-username= \ --docker-password= # can provide tokens too\ --docker-email= ```