Skip to content

Instantly share code, notes, and snippets.

@hasantayyar
Created March 10, 2019 20:03
Show Gist options
  • Save hasantayyar/e84714d3ed44ae2301472f1d24aef82d to your computer and use it in GitHub Desktop.
Save hasantayyar/e84714d3ed44ae2301472f1d24aef82d to your computer and use it in GitHub Desktop.
Deploy missing deployment to clusters
PROJECT="your-project-name"
SEARCH=$1
FILE=$2
CLUSTER_FILTER=$3
if [ -z $SEARCH ]; then
echo "Missing param. 1st param is the search phrase"
exit 1
fi
if [ -z $FILE ]; then
echo "Missing param. 2nd param is the config path"
exit 1
fi
if [ -z $CLUSTER_FILTER ]; then
echo "Missing param. 3nd param is the search term for clusters to be updated"
exit 1
fi
set -ex
for STR in $(gcloud container clusters list --filter="name:${CLUSTER_FILTER}" |awk '{print $1","$2}'); do
CLUSTER=$(echo $STR | cut -f1 -d,)
ZONE=$(echo $STR | cut -f2 -d,)
gcloud container clusters get-credentials $CLUSTER --zone $ZONE --project $PROJECT > /dev/null
CHECK=$(kubectl get pods |grep $SEARCH)
if [ -z $CHECK ];
then
echo ">>> Deploy $FILE to $CLUSTER"
kubectl apply $FILE
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment