Last active
November 16, 2020 14:07
-
-
Save phelian/aa217fe7a51e96d03b08d82a29446021 to your computer and use it in GitHub Desktop.
k8s helper scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
#Usage: k8s_delete deployment -dev | |
#Deletes all deployments containing "-dev". Usage with caution | |
func k8s_delete() { | |
for p in $(kubectl get $1 | grep -v NAME | cut -f1 -d' ' | grep $2); do | |
kubectl delete $1 $p; | |
done | |
} | |
#Usage: k8s_backup <list all resources that you want backuped> | |
#Example: k8s_backup deployment ingress configmap | |
func k8s_backup() { | |
RESOURCES=""; | |
for ARG in "$@"; do | |
RESOURCES+=",$ARG"; | |
done | |
RESOURCES=$(echo $RESOURCES | cut -c 2-); | |
IFS=$'\n'; | |
for resource in $(kubectl get $RESOURCES | grep -v NAME | cut -f1 -d' ');do | |
echo "Backing up $resource"; | |
SERVICE=$(echo $resource | cut -f1 -d'/' | cut -f1 -d'.'); | |
NAME=$(echo $resource | cut -f2 -d'/'); | |
kubectl get $SERVICE $NAME -o yaml > $SERVICE.$NAME.yaml; | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment