Google Container Registry (Artifact Registry)
Basics
Creating a repository, pushing an image, pulling an image, connecting repository to a Kubernetes cluster outside GCP
Create a repository
- Go to
https://console.cloud.google.com/artifacts/browse/<PROJECT_ID> - Create a repository through the wizard
- Copy the region and the repository name from the created resource
Connect to the repository and push an image
- Install the Google Cloud SDK
- Authenticate with
gcloud auth login - Configure Docker to use
gcloudas a credential helper:gcloud auth configure-docker REGION. For examplegcloud auth configure-docker europe-west3-docker.pkg.dev - Build a Docker image and tag it with the repository name:
docker build -t REGION/PROJECT_ID/REPOSITORY_NAME/IMAGE_NAME:TAG .. For exampledocker build -t europe-west3-docker.pkg.dev/my-project/my-repository/my-image:latest . - Push the image to the repository:
docker push REGION/PROJECT_ID/REPOSITORY_NAME/IMAGE_NAME:TAG. For exampledocker push europe-west3-docker.pkg.dev/my-project/my-repository/my-image:latest
Create a service account and connect to Kubernetes (using Helm)
-
Create a service account with the
Artifact Registry Readerrole -
Create a key for the service account and download it as a JSON file
-
Create a Kubernetes secret in a given namespace
kubectl create secret -n myapp docker-registry gcr-credentials \
--docker-server europe-west3-docker.pkg.dev \
--docker-username _json_key \
--docker-password DOWNLOADED_JSON_KEY_AS_SINGLE_LINE \
--docker-email dzarsky@dzarsky.eu -
Add the secret reference to the Helm values.yaml file
# ...
imagePullSecrets:
- name: gcr-credentials
# ...