Files
oam/knowledge base/kubectl.md
Michele Cereda 33e58da033 Added example
2022-04-20 09:28:27 +02:00

1.2 KiB

Kubectl

TL;DR

# list resources
kubectl get pods
kubectl get pods -n kube-system coredns-845757d86-47np2
kubectl get namespaces --show-labels
kubectl get services -o wide

# start a pod
kubectl run nginx --image nginx

# taint a node
kubectl taint nodes node1 key1=value1:NoSchedule

# taint all nodes in a certain nodepool (azure aks)
kubectl get nodes \
  -l "agentpool=nodepool1" \
  -o jsonpath='{.items[*].metadata.name}'
| xargs -n1 -I{} -p kubectl taint nodes {} key1=value1:NoSchedule

# remove a taint
# notice the '-' sign at the end
kubectl taint nodes node1 key1=value1:NoSchedule-

# delete non-default service accounts
kubectl delete serviceaccounts \
  $(kubectl get serviceaccounts -o jsonpath="{.items[?(@.metadata.name!='default')].metadata.name}" \
    | tr ' ' ',')

Further readings