Skip to content

Instantly share code, notes, and snippets.

@h2rd
Forked from olalonde/create-registry-secret.sh
Created September 17, 2017 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h2rd/88989ab473a2dfc05d7d66a458ecc7fa to your computer and use it in GitHub Desktop.
Save h2rd/88989ab473a2dfc05d7d66a458ecc7fa 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