Deletar evicted pods
kubectl get pods -n NAMESPACE | grep Evicted | awk '{print $1}' | xargs kubectl delete pod -n NAMESPACE
ou
kgp | grep Evicted | awk '{print $1}' | xargs kubectl delete pod
Deletar pods em crash
kubectl delete pod -n NAMESPACE `kubectl get pods -n NAMESPACE | awk '$3 == "CrashLoopBackOff" {print $1}'`
Deletar pods de um deploy
kubectl delete pod -n NAMESPACE `kubectl get pods -n NAMESPACE | awk '$1 ~ /^DEPLOY_NAME/ {print $1}'`
Listar pods de um deploy
kubectl -n NAMESPACE get pods | grep DEPLOY_NAME
Consultar qual pod do IP
kubectl get pods -o wide | grep $IP_DO_POD
PORT-FORWARD
kubectl port-forward --namespace NAMESPACE svc/SERVICE_NAME HOST_PORT:SERVICE_PORT
Builda todos os yaml e salva o output pra você analisar
helm template --values ./values-qas.yaml --output-dir manifests .
Recuperar um secret
kubectl get secrets SECRET_NAME -n NAMESPACE -o yaml | jq '.data | map_values(@base64d)'
Editar um secret
kubectl edit secret SECRET_NAME -n NAMESPACE
Recuperar valor de uma variavel de ambiente de um deployment
kubectl get deployment DEPLOY_NAME -o json | jq '.spec.template.spec.containers[0].env[] | select(.name == "ENV_VAR_NAME") | .'
Forçar rolling update de um deployment
#!/bin/bash
PATCH_JSON=("{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"$(date +'%s')\"}}}}}")
DEPLOY=$1
echo "Deploy => $DEPLOY"
for dep in $(kubectl get deployments | awk -v DEPLOY=$DEPLOY '$1 ~ "^" $DEPLOY {print $1}'); do
echo "Updating $dep"
kubectl patch deployment $dep -p $PATCH_JSON; sleep 5s;
done