Skip to main content
In this guide, you’ll learn how to use Mozilla SOPS with PGP (GPG) to securely encrypt and manage Kubernetes secrets in Git repositories.

Overview

SOPS (Secrets OPerationS) lets you encrypt structured files—YAML, JSON, and ENV—so they can be safely stored in public Git repos. It integrates with multiple key management systems:
For full SOPS documentation, see the Mozilla SOPS GitHub repository.

What Is PGP/GPG?

  • PGP: Pretty Good Privacy
  • GPG: GNU Privacy Guard (OpenPGP implementation)
Both provide strong encryption and decryption for secure data handling.

Step 1: Generate a GPG Key

Create a 3072-bit RSA key without passphrase or expiration:
Verify the fingerprint:
List and export your keys:

Step 2: Store the Private Key in Kubernetes

Create a Kubernetes Secret in the flux-system namespace:
Then delete the local key files:
Never commit sops.private.asc to Git. Only sops.pub.asc should be versioned.

Step 3: Encrypt a Kubernetes Secret with SOPS

Follow these steps:
  1. Generate a plain Secret manifest:
  2. Import the public key:
  3. Encrypt the file (or specific fields):
    Encrypted secret.yaml:
  4. Commit the encrypted secret.yaml to your Git repository.

Step 4: Decrypt with Flux’s Kustomize Controller

Configure your Kustomization to enable SOPS decryption:
With this setup, Flux’s Kustomize Controller will use the sops-gpg secret to decrypt and apply your secret.yaml inside the cluster.

Watch Video