Learn how to encrypt and manage your Kubernetes secrets in Git using Mozilla SOPS with a PGP key, then let FluxCD decrypt them automatically on apply.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- A Git repository with your application code checked out.
- Administrator-generated PGP keypair (public key committed in
infrastructure/SOPS/). - FluxCD installed in your cluster.
gpg,git,wget, andkubectlavailable on your machine.
Table of Contents
- Prepare the Repository
- Import the Public PGP Key
- Install SOPS
- Encrypt the Secret with SOPS
- Commit and Push
- Configure FluxCD Decryption
- Verify Decrypted Secret in Cluster
1. Prepare the Repository
Switch to your infrastructure branch and restore the plaintext secret for re-encryption.Always back up existing sealed or encrypted secrets before modifying them.
| Action | Command |
|---|---|
| Backup old Bitnami Sealed Secret | mv database/secret-mysql-sealed.yaml database/secret-mysql-sealed.yaml.bak |
| Restore plaintext secret manifest | mv database/secret-mysql-backup.yaml database/secret-mysql.yaml |
Secret at database/secret-mysql.yaml:
2. Import the Public PGP Key
On a fresh developer machine, confirm you have no existing public keys:CE284BB236654E42A):
You will use the PGP fingerprint with the
sops CLI to encrypt your secret.3. Install SOPS
Install the SOPS binary if it’s not already present:4. Encrypt the Secret with SOPS
Navigate to the directory containing your plaintext secret:data and stringData sections in place:
secret-mysql.yaml will include an sops: block:
Encryption Backends Supported by SOPS
| Backend | Description |
|---|---|
| PGP | Public-key encryption via GnuPG / GPG |
| AWS KMS | Key management using AWS Key Management Service |
| GCP KMS | Google Cloud Key Management Service integration |
| Azure Key Vault | Microsoft Azure Key Vault integration |
| HashiCorp Vault | Vault secret engine encryption |
5. Commit and Push
Add the encrypted secret to your Git repository and push:6. Configure FluxCD Decryption
FluxCD needs the private key stored in a KubernetesSecret (e.g., sops-gpg) and decryption enabled in the Kustomization manifest.
Edit infrastructure/flux/kustomization-database.yaml: