Created
October 20, 2021 08:24
-
-
Save akaron/33c47cc6e0a7c773c03a44bd6876a22b to your computer and use it in GitHub Desktop.
example: k8s patch script
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/bash | |
# get all deployments with name `redis-sentinel-manager` or `redis-cluster-manager` | |
# and patch these deploy with a nodeSelector with name similar to group-<ns>: <ns> | |
read -r -d '' tmpl <<'EOF' | |
kubectl -n i_ns patch deploy i_deploy --type='json' -p='[{"op": "add", "path": "/spec/template/spec/nodeSelector/group-i_ns", "value": "i_ns" }]' | |
EOF | |
# redis | |
ns_deploy=$(kubectl get deploy --all-namespaces|grep -E 'redis-.*-manager' | awk '{printf "%s+%s ", $1,$2}') | |
echo > patch_redis_1.sh | |
for i in ${ns_deploy} | |
do | |
i_ns=$(echo $i | tr '+' ' '|awk '{print $1}') | |
i_deploy=$(echo $i | tr '+' ' '|awk '{print $2}') | |
# backup existing yaml | |
kubectl -n ${i_ns} get deploy ${i_deploy} -o yaml > ${i_ns}_${i_deploy}_$(date +%Y%m%d).yaml | |
echo "${tmpl}" | sed "s|i_ns|${i_ns}|g" | sed "s|i_deploy|${i_deploy}|g" >> patch_redis_1.sh | |
done | |
echo "Run `bash patch_redis_1.sh`" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment