|
| 1 | += Setting up an image pull secret for a namespace |
| 2 | + |
| 3 | +Some external container registries (for example DockerHub) have fairly strict rate limits for unauthenticated pulls. |
| 4 | +We strongly recommend setting up an image pull secret for such registries. |
| 5 | +This page will guide you through the process of setting up an image pull secret for all workloads in a namespace. |
| 6 | + |
| 7 | +TIP: Since DockerHub is the most prominent container registry that enforces strict pull rate limits for unauthenticated pulls, we'll illustrate the process with DockerHub. |
| 8 | + |
| 9 | +== Prerequisites |
| 10 | + |
| 11 | +* You have a token for authenticating with the registry |
| 12 | +** for example a https://docs.docker.com/security/for-developers/access-tokens/["Personal access token"] for DockerHub |
| 13 | +* You have `admin` access to the namespace in which you want to setup the image pull secret |
| 14 | + |
| 15 | +== Creating the image pull secret |
| 16 | + |
| 17 | +. Login to the desired zone |
| 18 | ++ |
| 19 | +[source,bash] |
| 20 | +---- |
| 21 | +zone=ZONE-ID <1> |
| 22 | +namespace=NAMESPACE <2> |
| 23 | +oc login --web https://api.${zone}.appuio.cloud:6443 <3> |
| 24 | +oc project $namespace <4> |
| 25 | +---- |
| 26 | +<1> Replace `ZONE-ID` with the zone on which you want to access the registry. |
| 27 | +See the https://portal.appuio.cloud/zones[list of zones] for available {product} zones. |
| 28 | +<2> The namespace in which you want to create the image pull secret. |
| 29 | +<3> `oc login --web` may open a window or tab in your browser if you're not currently logged in on the zone. |
| 30 | +<4> Select the target namespace as the current project. |
| 31 | +This allows us to run commands targeting that namespace without `-n $namespace`. |
| 32 | + |
| 33 | +. Create the image pull secret from your token |
| 34 | ++ |
| 35 | +[source,bash] |
| 36 | +---- |
| 37 | +REGISTRY='https://index.docker.io/v1/' <1> |
| 38 | +USERNAME=<username> <2> |
| 39 | +TOKEN=<token> <3> |
| 40 | +SECRET_NAME=image-pull-secret <4> |
| 41 | +oc create secret docker-registry "$SECRET_NAME" \ |
| 42 | + --docker-username="$USERNAME" --docker-password="$TOKEN" |
| 43 | +---- |
| 44 | +<1> The URL of the registry. |
| 45 | +Change this if you're setting up a pull secret for a registry other than DockerHub. |
| 46 | +<2> The token for authenticating with the registry. |
| 47 | +For example a https://docs.docker.com/security/for-developers/access-tokens/["Personal access token"] for DockerHub. |
| 48 | +<3> Your user name on the registry. |
| 49 | +Check your registry's documentation for details on how to login using a token. |
| 50 | +For DockerHub, provide your Docker ID. |
| 51 | +<4> You can choose any name for the pull secret, but you must use the same name in the next section. |
| 52 | + |
| 53 | +== Link the image pull secret to the default service account in the namespace |
| 54 | + |
| 55 | +TIP: If you're using custom service accounts to run your workloads, repeat the instruction in this section for each service account that needs to pull images from the registry. |
| 56 | + |
| 57 | +. Add the image pull secret to the `default` service account |
| 58 | ++ |
| 59 | +[source,bash] |
| 60 | +---- |
| 61 | +SERVICEACCOUNT=default <1> |
| 62 | +oc secrets link "$SERVICEACCOUNT" "$SECRET_NAME" --for=pull |
| 63 | +---- |
| 64 | +<1> We link the pull secret to the `default` service account in the namespace. |
| 65 | +This is the service account that's used to run workloads when you don't specify a custom service account. |
0 commit comments