Skip to content

Instantly share code, notes, and snippets.

@besteban1989
Last active July 16, 2024 01:14
Show Gist options
  • Save besteban1989/f164a861b548553fde06c1d4990fe966 to your computer and use it in GitHub Desktop.
Save besteban1989/f164a861b548553fde06c1d4990fe966 to your computer and use it in GitHub Desktop.
Kubernetes snippets #swissknife #network #connectivity
# Run busybox
kubectl run -i --tty busybox --image=busybox --restart=Never -- sh
# Run SSH-client
kubectl run -i --tty ssh-client --image=kroniak/ssh-client --restart=Never -- sh
# Run busybox with curl included
kubectl run -i --tty busybox --image=yauritux/busybox-curl --restart=Never -- sh
# Test network connectivy by running netcat
nc -z -v -w5 <host> <port>
# Delete evicted pods in all namespaces
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace " $1} ' | xargs kubectl delete pod
# Delete evicted pods complete in all namespaces
kubectl get pods --all-namespaces | egrep 'Evicted|Error|OOMKilled|ContainerStatusUnknown' | awk '{print $2 " --namespace " $1} ' | xargs kubectl delete pod
# Scale all pods to 0 in a given namespace
kubectl scale deploy -n <namespace> --replicas=0 --all
# Restart all deployments in a namespace (switch to the namespace before running the command)
kubectl get deploy | awk '{print $1}' | xargs kubectl rollout restart deploy
# Delete volume attachment (useful when multi-attach volume issue is present in pods using PVCs)
kubectl get volumeattachment
kubectl delete volumeattachment <the-target-volume-attachment>
# Force uninstall an api service
kubectl get apiservice --all-namespaces
kubectl delete apiservice/<api-name> #example kubectl delete apiservice/v1beta1.external.metrics.k8s.io
# Restore dump file in posgre SQL
cat db_dump.sql | kubectl exec -i $POD_NAME -- env PGPASSWORD=$PASS psql -U $USERNAME -d $DATABASE
# Encode to base64 without new lines
echo -n '<the-string-to-be-encoded' | base64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment