Created
June 27, 2017 12:53
-
-
Save jmlrt/0bb4fdc1eaad182d11ae4fd081b3afa7 to your computer and use it in GitHub Desktop.
Update Kubernetes deployment image
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 | |
# | |
# Update docker image tag in a kubernetes deployment | |
# Kubernetes cluster address | |
K8S_CLUSTER="change.me" | |
# Kubernetes cluster certificate path | |
K8S_CERTIFICATE="/change/me" | |
# Kubernetes cluster token | |
K8S_USER="CHANGEME" | |
# Kubernetes cluster Token | |
K8S_TOKEN="CHANGEME" | |
# Docker registry server and credentials | |
REGISTRY_SERVER="https://change.me:5000" | |
REGISTRY_USER="CHANGEME" | |
REGISTRY_PASSWORD="CHANGEME" | |
# Kubernetes deployment | |
APP=$1 | |
# Docker image tag | |
VERSION=$2 | |
echo "\n-- Check if image exists in docker registry" | |
curl --head --fail --silent --show-error --insecure --basic --user ${REGISTRY_USER}:${REGISTRY_PASSWORD} \ | |
https://${REGISTRY_SERVER}/v2/${APP}/manifests/${VERSION} | |
if [ ! -x ./kubectl ]; then | |
echo "\n-- Download kubernetes client" | |
wget --quiet --output-document=./kubectl https://storage.googleapis.com/kubernetes-release/release/v1.6.3/bin/linux/amd64/kubectl | |
chmod +x ./kubectl | |
fi | |
echo "\n-- Check if kubernetes client is configured" | |
./kubectl config get-contexts ${K8S_USER} | |
if [ $? -ne 0 ]; then | |
echo "\n-- Configure kubernetes client" | |
./kubectl config set-cluster ${K8S_CLUSTER} \ | |
--embed-certs=true \ | |
--server=https://api.${K8S_CLUSTER} \ | |
--certificate-authority=${K8S_CERTIFICATE} | |
./kubectl config set-credentials ${K8S_USER} --token=${K8S_TOKEN} | |
./kubectl config set-context ${K8S_USER} \ | |
--cluster=${K8S_CLUSTER} \ | |
--user=${K8S_USER} | |
./kubectl config use-context ${K8S_USER} | |
fi | |
echo "\n-- Update deployment image" | |
./kubectl set image deployment/${APP}-deployment *=${REGISTRY_SERVER}/${APP}:${VERSION} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment