Deploying images from a private container registry¶
You can configure your Knative cluster to deploy images from a private registry across multiple Services and Revisions. To do this, you must create a list of Kubernetes secrets (imagePullSecrets) by using your registry credentials. You must then add those secrets to the default service account for all Services, or the Revision template for a single Service.
Prerequisites¶
- You must have a Kubernetes cluster with Knative Serving installed.
- You must have access to credentials for the private container registry where your container images are stored.
Procedure¶
-
Create a
docker-registrySecret in your target namespace. If your local$HOME/.docker/config.jsonstores direct registry credentials (rather than a hostcredsStorehelper), you can create the Secret from that file:kubectl create secret generic <registry-credential-secret> \ --namespace <namespace> \ --from-file=.dockerconfigjson="$HOME/.docker/config.json" \ --type=kubernetes.io/dockerconfigjsonIf your Docker configuration uses a credential helper (
credsStore), follow Pull an Image from a Private Registry in the Kubernetes documentation to create adocker-registrySecret instead. -
Choose one of the following to attach the Secret:
-
Single Service (recommended): reference
imagePullSecretson the Service's Revision template (replace<private-registry>/<repo>:<tag>with your private image):apiVersion: serving.knative.dev/v1 kind: Service metadata: name: private-app namespace: <namespace> spec: template: spec: imagePullSecrets: - name: <registry-credential-secret> containers: - image: <private-registry>/<repo>:<tag> ports: - containerPort: 8080 -
All Services in a namespace: patch the
defaultServiceAccount in that namespace so every Revision uses the Secret unlessserviceAccountNameis overridden:kubectl patch serviceaccount default \ --namespace <namespace> \ -p '{"imagePullSecrets": [{"name": "<registry-credential-secret>"}]}'
-
-
Apply the Service and verify it becomes ready and resolves the image digest on its latest Revision:
kubectl apply -f private-app.yaml kubectl wait kservice/private-app --namespace <namespace> --for=condition=Ready --timeout=120s REVISION=$(kubectl get kservice private-app --namespace <namespace> -o jsonpath='{.status.latestReadyRevisionName}') kubectl get revision "$REVISION" --namespace <namespace> -o jsonpath='{.status.containerStatuses[0].imageDigest}'; echo
If your private registry uses a custom CA certificate or sits behind a corporate proxy, your cluster administrator must also configure Registry trust and tag resolution.