Deploying images from a private container registry

Learn how to configure your Knative cluster to deploy images from a private container registry.

To share access to your private container images across multiple services and revisions, you create a list of Kubernetes secrets (imagePullSecrets) using your registry credentials, add that imagePullSecrets to your default service account, and then deploy those configurations to your Knative cluster.

Before you begin

You need:

  • A Kubernetes cluster with Knative Serving installed.
  • The credentials to the private container registry where your container images are stored.

Configuring your credentials in Knative

  1. Create a imagePullSecrets that contains your credentials as a list of secrets:

    1. kubectl create secret docker-registry [REGISTRY-CRED-SECRETS] \
    2. --docker-server=[PRIVATE_REGISTRY_SERVER_URL] \
    3. --docker-email=[PRIVATE_REGISTRY_EMAIL] \
    4. --docker-username=[PRIVATE_REGISTRY_USER] \
    5. --docker-password=[PRIVATE_REGISTRY_PASSWORD]

    Where

    • [REGISTRY-CRED-SECRETS] is the name that you want for your secrets (imagePullSecrets object). For example, container-registry.

    • [PRIVATE_REGISTRY_SERVER_URL] is the URL to the private registry where your container images are stored.

      Examples:

    • [PRIVATE_REGISTRY_EMAIL] is your email address that is associated with the private registry.

    • [PRIVATE_REGISTRY_USER] is the username that you use to access the private container registry.

    • [PRIVATE_REGISTRY_PASSWORD] is the password that you use to access the private container registry.

  1. Example:
  2. ```
  3. kubectl create secret `container-registry` \
  4. --docker-server=https://gcr.io/ \
  5. --docker-email=my-account-email@address.com \
  6. --docker-username=my-grc-username \
  7. --docker-password=my-gcr-password
  8. ```
  9. Tip: After creating the `imagePullSecrets`, you can view those secrets by running:
  10. ```
  11. kubectl get secret [REGISTRY-CRED-SECRETS] --output=yaml
  12. ```
  1. Add the imagePullSecrets to your default service account in the default namespace.

    Note: By default, the default service account in each of the namespaces of your Knative cluster are use by your revisions unless serviceAccountName is specified.

    Run the following command to modify your default service account, assuming you named your secrets container-registry:

    1. kubectl patch serviceaccount default -p "{\"imagePullSecrets\": [{\"name\": \"container-registry\"}]}"

Now, all the new pods that are created in the default namespace will include your credentials and have access to your container images in the private registry.

What’s next

You can now create a service that uses your container images from the private registry. Learn how to create a Knative service.