Skip to content

Instantly share code, notes, and snippets.

@olalonde
Created April 20, 2017 04:48
Show Gist options
  • Save olalonde/1dd5c572e3329fbae0a5a434709c45a6 to your computer and use it in GitHub Desktop.
Save olalonde/1dd5c572e3329fbae0a5a434709c45a6 to your computer and use it in GitHub Desktop.
Create a registry secret in Kubernetes
#!/bin/bash
rm /tmp/image-pull-secret.yaml
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 create -f - << EOF
apiVersion: v1
kind: Secret
metadata:
name: aws-ecr-registry
data:
.dockerconfigjson: $(echo $configjson | /usr/bin/base64)
type: kubernetes.io/dockerconfigjson
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment