The install flags only apply to fresh installs, because existing install commands ignore changes. The running cluster was encrypted by hand with the steps in the runbook.
7.5 KiB
Turn on k3s Secret encryption
Use this once to encrypt the Secrets in an existing cluster with secretbox. Don't use it for fresh installs, because 02-k8s-bootstrap turns on encryption during installation. Don't use it to rotate keys later either.
Steps 1–5 worked on the live cluster on 2026-12-01 with
v1.36.2+k3s1. They're based on the k3s guide for existing clusters and the source code for that version. The guide doesn't cover starting withsecretbox. If a check doesn't match, stop. Don't repeatrotate-keys, use--forceor delete k3s files.
Don't deploy 02, run the k3s installer or recreate VMs for this change.
Before you start
-
Check that you have current VM backups of all 3 masters. They contain unencrypted Secrets, so restrict access to them.
-
Pause deployments, and don't merge anything until you finish.
-
Check that you can reach each master directly over SSH, not only through the control-plane VIP.
-
From your workstation, check the nodes:
kubectl get nodesCheckpoint: all six nodes are
Ready, and the masters runv1.36.2+k3s1. -
On each master, check etcd and look for existing settings. The last two commands only print file or setting names:
sudo k3s kubectl get --raw=/readyz/etcd; echo sudo grep -rls 'secrets-encryption' /etc/rancher/k3s/ { systemctl cat k3s; sudo cat /etc/default/k3s /etc/sysconfig/k3s /etc/systemd/system/k3s.service.env 2>/dev/null; } | grep -oE -- '--config|--secrets-encryption|K3S_CONFIG_FILE'Checkpoint: each master prints only
ok. Any other output means etcd has a problem, encryption settings already exist or k3s uses a custom config path.
Restarting the masters
Steps 2 and 4 use this procedure. Restart k3s-master-1 first, then k3s-master-2, then k3s-master-3. On each one, run:
sudo systemctl restart k3s
sudo k3s kubectl get --raw=/readyz/etcd; echo
sudo k3s kubectl get nodes
Checkpoint: etcd returns ok and all nodes are Ready before you restart the next master. The API can take a minute to respond, so rerun the two checks if needed. Finish all 3 restarts without long breaks.
1. Enable encryption and add the settings
-
On
k3s-master-1, check the status:sudo k3s secrets-encrypt statusCheckpoint: it shows
Disabled, no configuration file found. -
On
k3s-master-1only, run this. It doesn't create a key or encrypt anything yet:sudo k3s secrets-encrypt enable -
On all 3 masters, add the settings in a separate file, so the existing config stays unchanged:
sudo mkdir -p /etc/rancher/k3s/config.yaml.d sudo install -m 600 /dev/stdin /etc/rancher/k3s/config.yaml.d/90-secrets-encryption.yaml <<'EOF' secrets-encryption: true secrets-encryption-provider: secretbox EOF
2. Restart and check the settings
-
On
k3s-master-1, check the status:sudo k3s secrets-encrypt statusCheckpoint: it shows
Disabled, stagestartandAll hashes match. -
From your workstation, check which encryption settings each master uses:
kubectl get nodes -l node-role.kubernetes.io/control-plane -o json | jq -r '.items[] | .metadata.name + ": " + (.metadata.annotations["k3s.io/node-args"] | fromjson | join(" ") | [scan("--secrets-encryption[^ ]*(?: (?!--)[^ ]+)?")] | join(" "))'Checkpoint: all 3 masters show
--secrets-encryptionset totrueand--secrets-encryption-providerset tosecretbox. Don't continue without both, because the next step uses the provider setting to choose the key type.
3. Encrypt the Secrets
Don't interrupt this step or restart any masters until it finishes. A crash could stop the cluster from starting (k3s issue 13763), and we haven't confirmed a fix.
-
On
k3s-master-1, run this once. It creates the key and re-encrypts the existing Secrets:sudo k3s secrets-encrypt rotate-keys -
Check the status until the stage is
reencrypt_finished:sudo k3s secrets-encrypt statusIf there's an error or no progress, check the logs with
sudo journalctl -u k3s --since '15 min ago', then stop. Don't runrotate-keysagain.
4. Restart and check the status
-
Restart all 3 masters again.
-
On
k3s-master-1, check the status:sudo k3s secrets-encrypt statusCheckpoint: it shows
Enabled,reencrypt_finished,All hashes matchand an activeXSalsa20-POLY1305key.
5. Verify
-
On each master, check that its API can read all Secrets. This doesn't print them:
sudo k3s kubectl get secrets -A -o name >/dev/null && echo okCheckpoint: each master prints
ok. -
From your workstation, create a test Secret with a fake value:
kubectl -n default create secret generic encryption-test --from-literal=value=not-a-real-secret -
On
k3s-master-1, check the test Secret and an existing Secret in etcd. This needsetcdctl. If it's missing, install it withsudo apt install etcd-client. The command only prints the first 21 characters of each stored value:for key in default/encryption-test heimdall/heimdall-tls; do sudo env ETCDCTL_API=3 etcdctl \ --endpoints=https://127.0.0.1:2379 \ --cacert=/var/lib/rancher/k3s/server/tls/etcd/server-ca.crt \ --cert=/var/lib/rancher/k3s/server/tls/etcd/client.crt \ --key=/var/lib/rancher/k3s/server/tls/etcd/client.key \ get "/registry/secrets/$key" --print-value-only | head -c 21 echo doneCheckpoint: both lines are
k8s:enc:secretbox:v1:. -
From your workstation, delete the test Secret, then check that your apps still work:
kubectl -n default delete secret encryption-test kubectl get pods -A --field-selector=status.phase!=Running,status.phase!=SucceededCheckpoint: no pods are listed, and the apps work normally.
6. Clean up
-
Make new VM backups of all 3 masters. Once they finish, delete the older ones, because their Secrets aren't encrypted. The new backups contain both the encrypted data and its key, so keep access restricted.
-
On each master, take a new etcd snapshot, then list the snapshots:
sudo k3s etcd-snapshot save --name after-secrets-encryption sudo k3s etcd-snapshot ls -
On the master that holds each snapshot, delete any taken before step 4 finished. Check the name and date first, and delete any copies stored elsewhere too:
sudo k3s etcd-snapshot delete <snapshot-name>Keep the remaining snapshots separate from the k3s server token. Someone with both can decrypt the Secrets.
-
Merge the
02change, then resume deployments. Don't deploy02.
If something goes wrong
Stop and save the status output and logs. Don't restore just one master from a VM backup. Its old etcd data and encryption settings may not match the other masters. Plan the recovery for all 3 masters together first. Restoring them loses any Kubernetes changes made after the backups and can leave them out of sync with the workers and Longhorn volumes.