Kyverno and private registry
Configure Kyverno to add private registry credentials to new Pods.
Clusters that download images from a private registry need to provide access credentials to each workload.
In an environment with many components — such as TDP Kubernetes — repeating this configuration manually in each chart is inefficient and creates a risk of inconsistency.
Kyverno solves this problem as a cluster policy engine: it intercepts Pod creation and automatically injects the required imagePullSecrets, based on a centralized ClusterPolicy.
This way, all components use the registry credentials without each manifest having to declare them individually.
This adjustment is conditional: it only applies when the environment requires authentication to download images from a private registry.
Environments that use public registries or configure imagePullSecrets directly in each chart do not need this step.
When to consider this adjustment
Consider this configuration when:
- images are distributed through a private registry
- the cluster needs to reuse the same credentials across multiple components
- the platform policy requires standardized use of
imagePullSecrets - you want to centralize the maintenance of these credentials
Kyverno's role in this context
The Secret remains the object that stores the registry credentials.
Kyverno's role is to apply and standardize the use of this Secret across the cluster through a ClusterPolicy.
This allows new Pods created in the configured namespaces to automatically receive the imagePullSecrets reference.
Kubernetes only uses an imagePullSecrets if the referenced Secret exists in the same namespace as the Pod.
If the tdp-registry Secret does not exist in the namespace where the Pod will be created, the image download fails even with the ClusterPolicy active, and the installation stays in ImagePullBackOff.
Create the Secret in each TDP namespace before creating Pods in that namespace.
Kyverno's ClusterPolicy acts at Pod creation time.
Existing workloads are not affected — only new Pods created after the policy is applied receive the imagePullSecrets.
To apply the credentials to existing workloads, recreate them (e.g., kubectl rollout restart deployment/<DEPLOYMENT_NAME> -n <NAMESPACE>).
Configuration overview
The flow consists of three steps:
- Install Kyverno in the cluster
- Create the registry Secret in each TDP namespace
- Create a
ClusterPolicythat automatically injectsimagePullSecretsinto Pods
1. Install Kyverno
helm repo add kyverno https://kyverno.github.io/kyverno/
helm repo update
helm install kyverno kyverno/kyverno --namespace kyverno --create-namespace
2. Create the registry Secret in each namespace
The Secret file contains registry access credentials in plain text.
Never commit this file to the Git repository.
Manage credentials through a specialized tool (Sealed Secrets, External Secrets Operator, HashiCorp Vault) or create the Secret manually in each namespace.
Create the tdp-registry.yaml file with the registry credentials:
apiVersion: v1
kind: Secret
metadata:
name: tdp-registry
type: kubernetes.io/dockerconfigjson
stringData:
.dockerconfigjson: |
{
"auths": {
"registry.tecnisys.com.br": {
"username": "<USERNAME>",
"password": "<PASSWORD>"
}
}
}
Apply it in each TDP namespace where the components will be installed:
kubectl apply -f tdp-registry.yaml -n <NAMESPACE>
Repeat for each TDP namespace (e.g., tdp, tdp-kafka, tdp-airflow, etc.) or automate it with a bootstrap script.
Kyverno also supports automatically copying Secrets between namespaces through a ClusterPolicy of type clone.
With this approach, create the Secret in a source namespace (e.g., kyverno) and Kyverno automatically replicates it to the destination namespaces.
See the Kyverno documentation for details on generate and clone.
3. Create the policy to inject imagePullSecrets
Create a policy-kyverno.yaml file:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: inject-tecnisys-registry-secret
annotations:
policies.kyverno.io/title: Inject Image Pull Secrets
policies.kyverno.io/description: Automatically adds the Tecnisys secret to all pods.
spec:
background: false
rules:
- name: inject-secret
match:
any:
- resources:
kinds:
- Pod
mutate:
patchStrategicMerge:
spec:
imagePullSecrets:
- name: tdp-registry
Apply the policy:
kubectl apply -f policy-kyverno.yaml
Expected result
After the ClusterPolicy is applied, new Pods created in the cluster receive the imagePullSecrets named tdp-registry, allowing them to download private images from the Tecnisys registry.
The Secret must exist in the Pod's namespace for Kubernetes to use it — confirm that the Secret exists in every TDP namespace before installing the components.
Where to store it in the GitOps repository
Commit only the policy-kyverno.yaml file to the GitOps repository in a policies/ folder:
tdp-gitops/
├── app-of-apps.yaml
├── apps/
├── values/
└── policies/
└── kyverno-registry.yaml
Do not commit the tdp-registry.yaml file containing credentials.
These policy files are applied with kubectl apply -f, as part of the environment bootstrap — Argo CD does not manage them directly as Applications.
The manifests in the policies/ folder are applied once, during the environment bootstrap.
They do not need to be managed by an Argo CD Application, but they can be if a platform Application is responsible for managing cluster policies.