Created
October 28, 2016 07:58
-
-
Save keegancsmith/81fed05aa33b460f7697156fbd016091 to your computer and use it in GitHub Desktop.
A way to more easily bulk update `k8s` specs, requires modification for your use case. Thought I'd share, since there is no nice way in k8s to partially update a bunch of resources. In this case I wanted to update resource constraints of most our deployments. `find some-magic-here | xargs -n1 ./k8s-patch.sh force`
This file contains 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 | |
# Use this script as an example of how to patch k8s resources. It currently | |
# patches the resource constraints. | |
set -e | |
ns=$(cat "$2" | jq -r '.metadata.namespace') | |
name=$(cat "$2" | jq -r '.kind + "/" + .metadata.name') | |
patch=$(cat "$2" | jq -c '{spec: {template: {spec: {containers: [.spec.template.spec.containers[] | {name: .name, resources: .resources}]}}}}') | |
if [ "$1" = "dry-run" ]; then | |
echo kubectl -n $ns patch $name -p "$patch" | |
elif [ "$1" = "force" ]; then | |
set -x | |
kubectl -n $ns patch $name -p "$patch" | |
else | |
echo "USAGE: k8s-patch.sh [dry-run|force] spec.json" | |
exit 2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment