Created
April 22, 2017 08:56
-
-
Save olalonde/263e33b50e8c7a8fa98bc0f42a07ba58 to your computer and use it in GitHub Desktop.
Create or update AWS registry secret on Kubernetes
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_registry_secret() { | |
login_cmd=$(aws ecr get-login) | |
username=$(echo $login_cmd | cut -d " " -f 4) | |
password=$(echo $login_cmd | cut -d " " -f 6) | |
endpoint=$(echo $login_cmd | cut -d " " -f 9) | |
auth=$(echo "$username:$password" | /usr/bin/base64) | |
configjson="{ \"auths\": { \"${endpoint}\": { \"auth\": \"${auth}\" } } }" | |
kubectl apply -f - << EOF | |
apiVersion: v1 | |
kind: Secret | |
metadata: | |
name: aws-ecr-registry | |
data: | |
.dockerconfigjson: $(echo $configjson | /usr/bin/base64) | |
type: kubernetes.io/dockerconfigjson | |
EOF | |
} | |
update_registry_secret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note to whomever want to use this, you might want to remove line ending to auth and add one in the yaml:
Also please note that the following command
does the same — see the documentation.