How to write a chart for imagePullSecret from gcr
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
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.
Related reading
- How to write a kubernetes pod configuration to start two containers
- How would I set up access to multiple Nodes with a single Service in kubernetes?
- HPA creates more pods than expected
- HTCONDORkubernetes / k8s Unable to start minicondor image within k8s - condor_master not working
- HttpContext.Connection.RemoteIpAddress returns private address for asp.net core in kubernetes
- Hyper-v and VirtualBox conflict in Dockers with Minikube
- I need to get resource usage of Pods in a Kubernetes Cluster with kubernetes python client
- I want to get the host MAC address in kubernetes pod where that pod runing on

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.