|
| 1 | +# Conditionally Rewrite Image Names for Local Registries |
| 2 | + |
| 3 | +This topic describes how to conditionally rewrite image names for local registries when using the HelmChart v2 custom resource. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Local image registries are required for air gap KOTS installations in existing clusters. Also, users in online environments can optionally use a local registry. For more information about how users configure a local image registry with KOTS, see [Configuring Local Image Registries](/enterprise/image-registry-settings). |
| 8 | + |
| 9 | +You can configure the KOTS HelmChart custom resource `optionalValues` key so that KOTS conditionally rewrites the names of images in your Helm values during deployment, depending on if the user configured a local registry. |
| 10 | + |
| 11 | +You can use the following KOTS template functions in the `optionalValues` key to conditionally rewrite image names: |
| 12 | +* [HasLocalRegistry](/reference/template-functions-config-context#haslocalregistry): Returns true if the installation environment is configured to use a local image registry. HasLocalRegistry is always true in air gap installations. HasLocalRegistry is also true in online installations if the user configured a local private registry. |
| 13 | +* [LocalRegistryHost](/reference/template-functions-config-context#localregistryhost): Returns the host of the local registry that the user configured. Alternatively, for air gap installations with Embedded Cluster or kURL, LocalRegistryHost returns the host of the built-in registry. |
| 14 | +* [LocalRegistryNamespace](/reference/template-functions-config-context#localregistrynamespace): Returns the namespace of the local registry that the user configured. Alternatively, for air gap installations with Embedded Cluster or kURL, LocalRegistryNamespace returns the namespace of the built-in registry. |
| 15 | + |
| 16 | + <details> |
| 17 | + <summary>What is the registry namespace?</summary> |
| 18 | + |
| 19 | + The registry namespace is the path between the registry and the image name. For example, `images.yourcompany.com/namespace/image:tag`. |
| 20 | + </details> |
| 21 | + |
| 22 | +## Prerequisite |
| 23 | + |
| 24 | +To support the use of local registries, configure the `builder` key. For more information about how to configure the `builder` key, see [`builder`](/reference/custom-resource-helmchart-v2#builder) in _HelmChart v2_. |
| 25 | + |
| 26 | +## Rewrite Application Image Names |
| 27 | + |
| 28 | +**Example:** |
| 29 | + |
| 30 | + ```yaml |
| 31 | + # KOTS HelmChart custom resource |
| 32 | + |
| 33 | + apiVersion: kots.io/v1beta2 |
| 34 | + kind: HelmChart |
| 35 | + metadata: |
| 36 | + name: samplechart |
| 37 | + spec: |
| 38 | + optionalValues: |
| 39 | + # Define the conditional statement in the when field |
| 40 | + - when: 'repl{{ HasLocalRegistry }}' |
| 41 | + values: |
| 42 | + postgres: |
| 43 | + image: |
| 44 | + registry: '{{repl LocalRegistryHost }}' |
| 45 | + repository: '{{repl LocalRegistryNamespace }}'/cloudnative-pg/cloudnative-pg |
| 46 | + ``` |
| 47 | +
|
| 48 | +## Rewrite the Replicated SDK Image Name |
| 49 | +
|
| 50 | +**Example:** |
| 51 | +
|
| 52 | +```yaml |
| 53 | + # KOTS HelmChart custom resource |
| 54 | + apiVersion: kots.io/v1beta2 |
| 55 | + kind: HelmChart |
| 56 | + metadata: |
| 57 | + name: samplechart |
| 58 | + spec: |
| 59 | + optionalValues: |
| 60 | + # Rewrite Replicated SDK image to local registry |
| 61 | + - when: 'repl{{ HasLocalRegistry }}' |
| 62 | + values: |
| 63 | + replicated: |
| 64 | + image: |
| 65 | + registry: '{{repl LocalRegistryHost }}' |
| 66 | + repository: '{{repl LocalRegistryNamespace }}/replicated-sdk' |
| 67 | + ``` |
| 68 | + |
| 69 | +## Add a Pull Secret for Rate-Limited Docker Hub Images {#docker-secret} |
| 70 | +
|
| 71 | +Docker Hub enforces rate limits for Anonymous and Free users. For more information about Docker Hub rate limiting, see [Understanding Docker Hub rate limiting](https://www.docker.com/increase-rate-limits) on the Docker website. |
| 72 | +
|
| 73 | +To avoid errors caused by reaching the rate limit, your users can run the `kots docker ensure-secret` command, which creates an `APP_SLUG-kotsadm-dockerhub` secret for pulling Docker Hub images and applies the secret to Kubernetes manifests that have images. For more information, see [Avoiding Docker Hub Rate Limits](/enterprise/image-registry-rate-limits). |
| 74 | + |
| 75 | +To support the use of the `kots docker ensure-secret` command, add the `APP_SLUG-kotsadm-dockerhub` pull secret (where `APP_SLUG` is your application slug) to any Docker images that could be rate-limited. |
| 76 | + |
| 77 | +**Example:** |
| 78 | + |
| 79 | +```yaml |
| 80 | +# kots.io/v1beta2 HelmChart custom resource |
| 81 | +apiVersion: kots.io/v1beta2 |
| 82 | +kind: HelmChart |
| 83 | +metadata: |
| 84 | + name: samplechart |
| 85 | +spec: |
| 86 | + values: |
| 87 | + image: |
| 88 | + registry: docker.io |
| 89 | + repository: org-name/example-docker-hub-image |
| 90 | + # Add the dockerhub secret |
| 91 | + pullSecrets: |
| 92 | + - name: gitea-kotsadm-dockerhub |
| 93 | +``` |
0 commit comments