Skip to main content
Version 3.0

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.

imagePullSecrets and namespace

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.

Mutation only affects new Pods

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:

  1. Install Kyverno in the cluster
  2. Create the registry Secret in each TDP namespace
  3. Create a ClusterPolicy that automatically injects imagePullSecrets into Pods

1. Install Kyverno​

Terminal input
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​

Do not commit the Secret containing credentials to Git

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:

tdp-registry.yaml
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:

Terminal input
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.

Alternative: synchronize through Kyverno CloneSecretPolicy

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:

policy-kyverno.yaml
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:

Terminal input
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.

Bootstrap vs. Argo CD

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.