Kubectl
Get Kube configs from the .kube config file
kubectl config get-contexts
Select specific cluster to work on
kubectl config use-context yourClusterName
Get Kubernetes pods
kubectl get pods
Restart deployments - sometimes useful when implementing a new config change or pulling an updated image
kubectl rollout restart deployments deploymentName
Find out the storage Class Names
kubectl get sc
Get the details of the persistent volume - including how they are attached etc
kubectl get pv
If your cluster finds it self in a difficult spot and being starved of resources. Your pods might start to get evicted because of "Disk Pressure" or some other error. If you do not action these quickly, you can end up with a high number of evicted pods in the cluster. How would you identify them and remove them?
you can use these two commands:
To Identify them:
kubectl get pods --all-namespaces -o json | jq '.items[] | select(.status.reason=="Evicted") | {namespace: .metadata.namespace, name: .metadata.name, status: .status.phase, reason: .status.reason}'
To Remove them:
kubectl get pods --all-namespaces -o json | jq '.items[] | select(.status.reason!=null) | select(.status.reason | contains("Evicted")) | "kubectl delete pod \(.metadata.name) -n \(.metadata.namespace)"' | xargs -n 1 bash -c
Last updated