- Generate a GPG keypair (public + private).
- Export the public key into your Git repository so developers can encrypt secrets.
- Store the private key as a Kubernetes Secret so Flux (or another controller) can decrypt SOPS-encrypted resources.
Never commit private keys to Git. Only the public key is suitable for a repository. Protect private keys — restrict access to cluster administrators or a secure key management system.
Summary of generated artifacts
Prerequisites & links
- gpg (GnuPG) installed on the admin workstation.
- kubectl configured with cluster admin privileges.
- Familiarity with SOPS and Flux: see Mozilla SOPS and Flux docs below.
- Mozilla SOPS: https://github.com/mozilla/sops
- Flux SOPS integration: https://fluxcd.io/docs/guides/mozilla-sops/
- Kubernetes Secrets: https://kubernetes.io/docs/concepts/configuration/secret/
- GnuPG documentation: https://gnupg.org/documentation/
1) Generate a GPG keypair (non-interactive)
Create an RSA 3072-bit keypair without a passphrase for automated use. This example uses a non-interactive batch heredoc. AdjustName-Real, Name-Email, and Name-Comment for your environment.
CE284BB23665E42A. You can also use the full 40-character fingerprint for unambiguous references.
2) Verify the generated keys
List the public key (use the 16-character key ID or full fingerprint):secindicates a secret (private) key.pubindicates a public key entry.
3) Export the private key (for storing into the cluster)
Export the private key in ASCII-armored format to a file (for examplesops-gpg.key). Keep this file secure and never commit it to source control.
4) Export the public key (to commit to Git)
Export the public key in ASCII-armored format and place it in your repository (for examplesops/sops-gpg.pub). This public key is what developers use to encrypt secrets.
sops-gpg.pub to your Git repository so application teams can use it to encrypt secrets.
5) Create a Kubernetes Secret containing the private key (Flux will use this for decryption)
Before running the command below, ensure you are targeting the correct cluster and namespace.Storing private keys in Kubernetes requires careful RBAC and etcd access controls. Ensure only authorized controllers and admins can read this Secret. Never store the private key in Git.
sops-gpg in the flux-system namespace from the private key file and name the key inside the Secret sops.asc:
- The
sops.ascfilename inside the Secret is a common convention; Flux’s SOPS integration can be configured to look for this filename. - Kubernetes Secrets are base64-encoded objects in etcd — secure etcd and RBAC accordingly.
6) (Optional) Delete the local keys from the GPG keyring
If you want to remove the keys from the admin workstation after exporting them, delete the secret and public keys by fingerprint. Interactive deletion:7) Commit the public key to Git
Commit thesops-gpg.pub file to your repository so developers and CI pipelines can encrypt secrets using the public key:
Final notes
-
Admin workflow summary:
- Admin generates the GPG keypair.
- Public key is committed to Git for developers to encrypt secrets.
- Private key is stored as a Kubernetes Secret for Flux to decrypt SOPS-encrypted manifests at apply time.
- Optionally remove local key material once exported and stored securely.
-
This article covers the administrator side only. It does not cover developer-side encryption with
sopsor Flux’s runtime decryption behavior. For those topics, see:- Flux SOPS integration: https://fluxcd.io/docs/guides/mozilla-sops/
- Mozilla SOPS: https://github.com/mozilla/sops