You are here: Home » kubernetes » kubectl
Kubernetes:kubectl
This is an old revision of the document!
Pods
Delete terminated pods
#!/bin/sh
for namespace in $(kubectl get ns | awk '{print $1}' | grep -v NAME); do
for pod in $(kubectl get pod -n $namespace --field-selector=status.phase!=Running | grep Terminated | awk '{print $1}' | grep -v NAME); do
kubectl delete pod -n "$namespace" "$pod"
done
done
Get all pods running on a node
function kpodnode() {
kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=$1
}
Secrets
Create secret manifest from literal
kubectl create secret generic [secret-name] -o yaml --dry-run --from-literal='ENV_VAR1=value1' \ --from-literal='ENV_VAR2=value2'
Create secret from file
kubectl create secret generic [secret-name] -o yaml --dry-run --from-file [filepath]
Get secrets with name wildcard
kubectl get secret --no-headers=true | awk '/db-container-v8-credentials/{print $1}' | xargs kubectl delete secret
Wait
Wait for resource deletion
kubectl wait --for=delete kind/name -n default --timeout=1200s