gpg, export the keys for use with Mozilla SOPS and FluxCD, and then securely clean up local key material. This workflow enables encrypted secrets in GitOps pipelines, ensuring that only Flux can decrypt them in-cluster.
1. Install & Review GPG
First, confirm thatgpg is installed:
| Option | Description | Example |
|---|---|---|
-o, --output | Write output to a specific file | gpg -o file.txt --decrypt secret.gpg |
-s, --sign | Create a signature | gpg -s document.txt |
-e, --encrypt | Encrypt for specified recipient | gpg -e -r alice document.txt |
--list-keys | List public keys | gpg --list-keys alice |
--list-secret-keys | List secret keys | gpg --list-secret-keys |
--armor | ASCII-armored output | gpg --armor --export [email protected] |
You can run
gpg --help for a full list of options. Use --openpgp to enforce strict OpenPGP behavior.2. Generate a GPG Key Pair
Create a 3072-bit RSA primary key and subkey with no passphrase or expiration. Replace the real name, email, and comment as needed:65DD426C08931CDEB33F4DCCE248B2366542A). You’ll use this in subsequent commands.
3. List and Verify Your Keys
View all public keys:4. Export Keys for SOPS & Flux
4.1 Export the Private Key
Keep
sops-gpg.key confidential. This private key will be stored in-cluster as a Kubernetes secret. Never commit it to Git.4.2 Export the Public Key
Prepare a directory in your Git repository for the public key:sops-gpg.pub so that developers can encrypt secrets:
5. Create a Kubernetes Secret for Flux
Import the private key into theflux-system namespace:
6. Clean Up Local GPG Material
Once the keys are exported and stored:7. Summary
You have successfully:- Generated a 3072-bit OpenPGP key pair without passphrase or expiry.
- Exported and committed the public key for developer usage.
- Created a Kubernetes secret containing the private key for FluxCD.
- Cleared all local key material to maintain security.
sops-gpg.pub in your GitOps repository—Flux will automatically decrypt them in-cluster.