Skip to content

Instantly share code, notes, and snippets.

@integrii
Last active November 8, 2018 04:52
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 integrii/b702593324c4a1aef2803287f10c9c1a to your computer and use it in GitHub Desktop.
Save integrii/b702593324c4a1aef2803287f10c9c1a to your computer and use it in GitHub Desktop.
Create a Google Image Host Secret
You can create the file with the following script. The script creates the necessary Google Cloud Platform (GCP) service account and gives it access to the registry.
# create a GCP service account; format of account is email address
SA_EMAIL=$(gcloud iam service-accounts --format='value(email)' create k8s-gcr-auth-ro)
# create the json key file and associate it with the service account
gcloud iam service-accounts keys create k8s-gcr-auth-ro.json --iam-account=$SA_EMAIL
# get the project id
PROJECT=$(gcloud config list core/project --format='value(core.project)')
# add the IAM policy binding for the defined project and service account
gcloud projects add-iam-policy-binding $PROJECT --member serviceAccount:$SA_EMAIL --role roles/storage.objectViewer
Then create the secret and specify the file that you just created:
SECRETNAME=varSecretName
kubectl create secret docker-registry $SECRETNAME \
--docker-server=https://gcr.io \
--docker-username=_json_key \
--docker-email=user@example.com \
--docker-password="$(cat k8s-gcr-auth-ro.json)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment