Useful Kubernetes Tricks

Useful Kubernetes Tricks

Find which RoleBinding/ClusterRoleBinding is related to a ServiceAccount

kubectl get clusterrolebindings -o json | jq -r '
  .items[] | 
    .subjects // [] | .[] | 
    [.kind,.namespace,.name] == ["ServiceAccount","kube-system","node-controller"]
  ) |'
kubectl get clusterrolebindings -o json | jq -r '.items[] | select(.subjects // [] | .[] | [.name] == ["<YOUR_ACCOUNT_NAME>"] ) |'

kubectl get rolebindings --all-namespaces -o json | jq -r '.items[] | select(.subjects // [] | .[] | [.name] == ["<YOUR_ACCOUNT_NAME>"] ) |'

Force iptables re-sync

kubectl delete pod -l component=kube-proxy -n kube-system

Delete namespace in terminating state

  1. kubectl get namespace <your_namespace> -o json > tmp.json
  2. Open tmp.json and remove any lines from finalizers. Just save it!
  3. kubectl proxy
  4. curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json<your_namespace>/finalize
  5. kubectl delete namespace <your_namespace>
  6. If you have any other namespaces that you want to delete, just replace <your_namespace> with new namespace name.

Downgrade Helm Application

helm install stable/nginx-ingress --version v0.23.0

Batch Delete CustomResourceDefinition/Secret

kubectl get customresourcedefinition  | grep 'kubeless'|awk '{print $1}'|xargs kubectl delete customresourcedefinition

kubectl get secret --all-namespaces | grep 'istio' |awk '{print $1 " " $2}' | xargs -n2 sh -c 'kubectl delete secret -n $0 $1'

Share Tweet Send
You've successfully subscribed to Unofficial Azure Club
Great! Next, complete checkout for full access to Unofficial Azure Club
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.