How to write a chart for imagePullSecret from gcr
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If a Helm chart needs to pull private images from GCR, the chart usually should not hardcode one secret name and hope every cluster matches it. A better design is to let the chart either reference an existing imagePullSecret or create one from provided registry credentials, then wire that secret into the pod spec.
Prefer an Existing Secret When Possible
In many production clusters, the image pull secret is created outside the application chart by platform tooling, GitOps, or external secret management. Your chart should support that directly.
A practical values.yaml shape is:
Then in the deployment template:
This is the simplest and most reusable pattern.
Optional Secret Creation Inside the Chart
If you do want the chart to create the secret, make it opt-in and explicit. One common pattern is to accept a base64-encoded Docker config JSON or the raw JSON key material used to build one.
values.yaml:
Secret template:
Then the pod can reference either the created secret or a pre-existing one with the same name.
Reference the Secret from the Workload
The secret does nothing unless the pod spec references it.
If your chart supports both created and existing secrets, make sure the name is the single source of truth so you do not duplicate configuration paths unnecessarily.
Keep Secret Handling Out of Plaintext Defaults
Do not commit real registry credentials into values.yaml. The chart should define the schema, not the secret value itself.
Good patterns are:
- pass secret values at deploy time
- use encrypted values files
- use external secret operators
- reference an existing secret managed elsewhere
For most teams, "chart references an existing secret" is the safest default.
GCR and Artifact Registry Note
Many clusters now use Artifact Registry rather than older GCR flows, but the Kubernetes-side behavior is the same: the pod needs credentials in a Docker registry secret format unless workload identity or another platform integration already solves it.
That means the Helm chart design still holds even if the backing registry endpoint changes.
Template Guardrails
It is worth adding a small condition so the deployment only renders imagePullSecrets when values are actually provided.
That keeps the manifest clean for clusters that use only public images.
Common Pitfalls
The biggest mistake is creating the secret but never referencing it in the pod spec. Kubernetes will not use it automatically.
Another issue is storing real registry credentials directly in the chart repository. That turns a deployment convenience into a credential-leak risk.
A third problem is hardcoding one secret name without making it configurable, which makes the chart painful to reuse across namespaces and clusters.
Summary
- Let the chart reference an existing
imagePullSecretby default. - Support chart-managed secret creation only as an explicit option.
- Wire the secret into the pod
imagePullSecretsfield. - Keep registry credentials out of committed plaintext values files.
- Design the chart so the secret name is configurable and reusable across environments.

