4 minute read
In Kubernetes, to pull images from private container image registries you either have to specify an image pull Secret (see Pull an Image from a Private Registry) or you have to configure the kubelet to dynamically retrieve credentials using a credential provider plugin (see Configure a kubelet image credential provider). When pulling an image, the kubelet is providing the credentials to the CRI implementation. The CRI implementation uses the provided credentials against the upstream registry to pull the image.
The registry-cache extension is using the Distribution project as pull through cache implementation. The Distribution project does not use the provided credentials from the CRI implementation while fetching an image from the upstream. Hence, the above-described scenarios such as configuring image pull Secret for a Pod or configuring kubelet credential provider plugins don’t work out of the box with the pull through cache provided by the registry-cache extension. Instead, the Distribution project supports configuring only one set of credentials for a given pull through cache instance (for a given upstream).
This document describe how to supply credentials for the private upstream registry in order to pull private image with the registry cache.
Create an immutable Secret with the upstream registry credentials in the Garden cluster:
kubectl create -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: ro-docker-secret-v1
namespace: garden-dev
type: Opaque
immutable: true
data:
username: $(echo -n $USERNAME | base64 -w0)
password: $(echo -n $PASSWORD | base64 -w0)
EOF
For Artifact Registry, the username is _json_key
and the password is the service account key in JSON format. To base64 encode the service account key, copy it and run:
echo -n $SERVICE_ACCOUNT_KEY_JSON | base64 -w0
Add the newly created Secret as a reference to the Shoot spec, and then to the registry-cache extension configuration.
In the registry-cache configuration, set the secretReferenceName
field. It should point to a resource reference under spec.resources
. The resource reference itself points to the Secret in project namespace.
apiVersion: core.gardener.cloud/v1beta1
kind: Shoot
# ...
spec:
extensions:
- type: registry-cache
providerConfig:
apiVersion: registry.extensions.gardener.cloud/v1alpha3
kind: RegistryConfig
caches:
- upstream: docker.io
secretReferenceName: docker-secret
# ...
resources:
- name: docker-secret
resourceRef:
apiVersion: v1
kind: Secret
name: ro-docker-secret-v1
# ...
Warning
Do not delete the referenced Secret when there is a Shoot still using it.
To rotate registry credentials perform the following steps:
ro-docker-secret-v2
) with the newly generated credentials as described in step 1. in How to configure the registry cache to use upstream registry credentials?.ro-docker-secret-v1
).Was this page helpful?