Skip to content

Deploying Bitnami Sealed Secrets on a kubeadm cluster with key rotation

Install the Sealed Secrets controller on a kubeadm 1.30 cluster, seal application secrets that can live in git, and rotate the sealing key without breaking existing SealedSecret manifests.

You inherit a kubeadm cluster where every database password, Stripe key, and SMTP credential lives in a plaintext Secret manifest in a private git repo “because the repo is private.” Three months in, a junior dev opens a public PR mirror by accident and the rotation that follows takes a full weekend across four customers. The fix that should have been there from week one is not “stop committing secrets” — it’s a controller that lets you commit a ciphertext only the cluster can decrypt, plus a key-rotation plan you can actually run without paging the on-call.

What’s happening

Sealed Secrets is an asymmetric-encryption controller for Kubernetes. You install the controller in kube-system; it generates an X.509 keypair on first start, publishes the public certificate, and watches the cluster for SealedSecret custom resources. On your laptop, kubeseal fetches that public cert, encrypts a Secret payload, and writes a SealedSecret manifest that is safe to commit to a public repo — only the cluster holding the private key can decrypt it, and only into the namespace and name the sealer specified. The controller decrypts each SealedSecret into a regular Secret that pods consume normally.

The two operational concerns most people skip on day one are key rotation and disaster recovery. The controller rotates its sealing keys on a schedule (default: 30 days), keeps old keys for decryption, and re-encrypts old SealedSecrets lazily. If you lose every replica without exporting the keys, every SealedSecret in git is now an unrecoverable blob. The fix below installs the controller in HA mode (three replicas, one active sealer at any time), takes a key backup the moment after first install, and gives you a cron script that exports keys nightly to an off-cluster encrypted bucket.

How to verify

After installing, the controller pods should be ready and the sealing key should be visible as a labeled Secret:

kubectl -n kube-system get pods -l app.kubernetes.io/name=sealed-secrets
# NAME                              READY   STATUS    AGE
# sealed-secrets-controller-xxxx    1/1     Running   2m
# sealed-secrets-controller-yyyy    1/1     Running   2m
# sealed-secrets-controller-zzzz    1/1     Running   2m

kubectl -n kube-system get secrets \
  -l sealedsecrets.bitnami.com/sealed-secrets-key=active \
  -o custom-columns=NAME:.metadata.name,CREATED:.metadata.creationTimestamp

Fetch the public cert and seal a test secret:

kubeseal --fetch-cert > /tmp/pub-cert.pem
kubectl create secret generic test-db \
  --from-literal=password=hunter2 \
  --namespace=default --dry-run=client -o yaml \
  | kubeseal --cert /tmp/pub-cert.pem -o yaml \
  > /tmp/test-db-sealed.yaml

kubectl apply -f /tmp/test-db-sealed.yaml
kubectl -n default get secret test-db -o jsonpath='{.data.password}' | base64 -d
# hunter2

If the last command prints hunter2, the controller is decrypting correctly and the sealing key is active.

The fix

Save the script as /root/install-sealed-secrets.sh on the kubeadm control-plane node and run it as root. It performs the full installer for an AlmaLinux 9 control plane: prerequisites check (kubectl, cluster reachable), Helm 3.15 install, Bitnami chart 2.16.x deployment of Sealed Secrets controller 0.27 in HA mode with three replicas, key rotation every 30 days, anti-affinity across nodes, PSA-compliant security context, kubeseal client install on the operator’s laptop, an etcd snapshot before changes, a first-key backup to /root/sealed-secrets-keys/ (the off-cluster sync is a follow-up), and a kubeseal smoke test against a temporary secret.

#!/usr/bin/env bash
set -euo pipefail

### kubeadm 1.30 — install Sealed Secrets controller (HA, 3 replicas)
### Run on the control-plane node as root
### Assumes: kubectl works from this node, cluster has at least 3 worker nodes

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

# === EDIT ===
SS_CHART_VERSION="2.16.1"      # bitnami-labs/sealed-secrets chart
SS_APP_VERSION="0.27.1"        # controller image tag
SS_NAMESPACE="kube-system"
SS_RELEASE="sealed-secrets"
KEY_BACKUP_DIR="/root/sealed-secrets-keys"
KEY_ROTATION="720h"            # 30 days
# ============

echo
echo "========================================"
echo "Sealed Secrets controller — kubeadm"
echo "========================================"
echo

echo "==> Prerequisite check"
command -v kubectl >/dev/null || { echo "kubectl not installed"; exit 1; }
kubectl cluster-info >/dev/null || { echo "kubectl cannot reach cluster"; exit 1; }

NODES=$(kubectl get nodes --no-headers | wc -l)
if (( NODES < 3 )); then
  echo "Cluster has only ${NODES} nodes — HA install expects >= 3"
  exit 1
fi

echo "==> Pre-flight etcd snapshot"
ETCDCTL_API=3 etcdctl \
  --endpoints=https://127.0.0.1:2379 \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  snapshot save "/root/etcd-snapshot-pre-ss-$(date +%Y%m%d-%H%M%S).db"

echo "==> Install Helm 3.15"
if ! command -v helm >/dev/null; then
  curl -fsSL https://baltocdn.com/helm/signing.asc \
    | gpg --dearmor -o /usr/share/keyrings/helm.gpg
  echo "deb [signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" \
    > /etc/apt/sources.list.d/helm-stable.list 2>/dev/null \
    || dnf -y install https://get.helm.sh/helm-v3.15.4-linux-amd64.tar.gz \
       || {
         curl -fsSL https://get.helm.sh/helm-v3.15.4-linux-amd64.tar.gz \
           -o /tmp/helm.tar.gz
         tar -C /tmp -xzf /tmp/helm.tar.gz
         install -m 0755 /tmp/linux-amd64/helm /usr/local/bin/helm
       }
fi
helm version --short

echo "==> Adding Bitnami Sealed Secrets chart repo"
helm repo add sealed-secrets https://bitnami-labs.github.io/sealed-secrets
helm repo update

echo "==> Writing values file"
mkdir -p /etc/sealed-secrets
cat > /etc/sealed-secrets/values.yaml <<EOF
fullnameOverride: sealed-secrets-controller
image:
  repository: bitnami/sealed-secrets-controller
  tag: ${SS_APP_VERSION}
  pullPolicy: IfNotPresent

replicaCount: 3

priorityClassName: system-cluster-critical

resources:
  requests:
    cpu: 100m
    memory: 128Mi
  limits:
    cpu: 500m
    memory: 256Mi

securityContext:
  runAsNonRoot: true
  runAsUser: 1001
  readOnlyRootFilesystem: true
  allowPrivilegeEscalation: false
  capabilities:
    drop:
      - ALL
  seccompProfile:
    type: RuntimeDefault

podSecurityContext:
  fsGroup: 65534
  runAsNonRoot: true
  runAsUser: 1001

# Key rotation cadence — new active key every 30 days
commandArgs:
  - --key-renew-period=${KEY_ROTATION}
  - --rate-limit=10
  - --rate-limit-burst=20

# Anti-affinity so the three replicas spread across nodes
affinity:
  podAntiAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchLabels:
            app.kubernetes.io/name: sealed-secrets
        topologyKey: kubernetes.io/hostname

metrics:
  serviceMonitor:
    enabled: false   # flip true once Prometheus Operator is installed

ingress:
  enabled: false
EOF

echo "==> Installing Sealed Secrets controller"
helm upgrade --install "${SS_RELEASE}" sealed-secrets/sealed-secrets \
  --namespace "${SS_NAMESPACE}" \
  --version "${SS_CHART_VERSION}" \
  -f /etc/sealed-secrets/values.yaml \
  --wait --timeout 5m

echo "==> Waiting for pods to be Ready"
kubectl -n "${SS_NAMESPACE}" rollout status deploy/sealed-secrets-controller --timeout=5m

echo "==> Installing kubeseal client (server arch only)"
KS_VERSION="${SS_APP_VERSION}"
KS_ARCH="$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')"
curl -fsSL "https://github.com/bitnami-labs/sealed-secrets/releases/download/v${KS_VERSION}/kubeseal-${KS_VERSION}-linux-${KS_ARCH}.tar.gz" \
  -o /tmp/kubeseal.tar.gz
tar -C /tmp -xzf /tmp/kubeseal.tar.gz kubeseal
install -m 0755 /tmp/kubeseal /usr/local/bin/kubeseal
kubeseal --version

echo "==> First-time key backup"
mkdir -p "${KEY_BACKUP_DIR}"
chmod 700 "${KEY_BACKUP_DIR}"

BACKUP_FILE="${KEY_BACKUP_DIR}/sealed-secrets-keys-$(date +%Y%m%d-%H%M%S).yaml"
kubectl -n "${SS_NAMESPACE}" get secrets \
  -l sealedsecrets.bitnami.com/sealed-secrets-key \
  -o yaml > "${BACKUP_FILE}"
chmod 600 "${BACKUP_FILE}"

# Encrypt the export at rest — this is the bootstrap recovery file
if command -v age >/dev/null; then
  AGE_RECIPIENT_FILE="${KEY_BACKUP_DIR}/recipient.txt"
  if [[ ! -f "${AGE_RECIPIENT_FILE}" ]]; then
    echo "WARNING: ${AGE_RECIPIENT_FILE} not present. Encrypt ${BACKUP_FILE} now with your own KMS or age recipient before leaving the box."
  else
    age -R "${AGE_RECIPIENT_FILE}" -o "${BACKUP_FILE}.age" "${BACKUP_FILE}"
    shred -u "${BACKUP_FILE}"
    BACKUP_FILE="${BACKUP_FILE}.age"
  fi
else
  echo "WARNING: age not installed — backup at ${BACKUP_FILE} is in cleartext."
  echo "Encrypt and sync off-cluster before considering this complete."
fi

echo "==> Installing nightly key-export cron"
cat > /etc/cron.daily/sealed-secrets-key-export <<'CRON'
#!/usr/bin/env bash
set -euo pipefail
DEST="/root/sealed-secrets-keys"
mkdir -p "${DEST}"
TS="$(date +%Y%m%d-%H%M%S)"
FILE="${DEST}/sealed-secrets-keys-${TS}.yaml"
kubectl -n kube-system get secrets \
  -l sealedsecrets.bitnami.com/sealed-secrets-key \
  -o yaml > "${FILE}"
chmod 600 "${FILE}"
# Encrypt with age and sync to off-cluster bucket
if [[ -f "${DEST}/recipient.txt" ]] && command -v age >/dev/null; then
  age -R "${DEST}/recipient.txt" -o "${FILE}.age" "${FILE}"
  shred -u "${FILE}"
  FILE="${FILE}.age"
fi
# Off-cluster sync — adjust to your object store
if command -v rclone >/dev/null; then
  rclone copy "${FILE}" remote:sealed-secrets-keys/ || true
fi
# Retain 30 days locally
find "${DEST}" -name 'sealed-secrets-keys-*' -mtime +30 -delete
CRON
chmod 0755 /etc/cron.daily/sealed-secrets-key-export

echo "==> Smoke test: seal + apply + verify"
TEST_NS="sealed-secrets-smoke"
kubectl create ns "${TEST_NS}" --dry-run=client -o yaml | kubectl apply -f -

kubeseal --fetch-cert > /tmp/pub-cert.pem

kubectl create secret generic smoke \
  --from-literal=token="ok-$(date +%s)" \
  --namespace="${TEST_NS}" \
  --dry-run=client -o yaml \
  | kubeseal --cert /tmp/pub-cert.pem -o yaml \
  > /tmp/smoke-sealed.yaml

kubectl apply -f /tmp/smoke-sealed.yaml
sleep 3

VAL="$(kubectl -n "${TEST_NS}" get secret smoke -o jsonpath='{.data.token}' | base64 -d)"
if [[ "${VAL}" =~ ^ok- ]]; then
  echo "Smoke test PASSED — controller decrypted SealedSecret into Secret"
else
  echo "Smoke test FAILED — got: ${VAL}"
  exit 1
fi
kubectl delete ns "${TEST_NS}" --wait=false

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Controller release: ${SS_RELEASE}"
echo "Replicas:"
kubectl -n "${SS_NAMESPACE}" get pods -l app.kubernetes.io/name=sealed-secrets -o wide
echo
echo "Active sealing keys:"
kubectl -n "${SS_NAMESPACE}" get secrets \
  -l sealedsecrets.bitnami.com/sealed-secrets-key \
  -o custom-columns=NAME:.metadata.name,LABEL:.metadata.labels.sealedsecrets\\.bitnami\\.com/sealed-secrets-key,AGE:.metadata.creationTimestamp
echo
echo "Key backup: ${BACKUP_FILE}"
echo "Nightly export cron: /etc/cron.daily/sealed-secrets-key-export"
echo
echo "On developer laptops, install kubeseal and run:"
echo "  kubeseal --fetch-cert > pub-cert.pem"
echo "  cat secret.yaml | kubeseal --cert pub-cert.pem -o yaml > sealed.yaml"

Make it executable and run once on the control-plane:

chmod 700 /root/install-sealed-secrets.sh
/root/install-sealed-secrets.sh

After install, the rotation workflow you need to remember is short: the controller rotates the active sealing key on the configured cadence, leaves the old keys labeled sealedsecrets.bitnami.com/sealed-secrets-key=compromised (the original label, misleading name — it just means “decryption-only”), and writes a new =active key. To force a re-seal of every committed SealedSecret against the new active key, run kubeseal --re-encrypt -f sealed.yaml -o yaml | sponge sealed.yaml and commit. To recover into a new cluster, restore the keys with kubectl apply -f sealed-secrets-keys.yaml -n kube-system before installing the chart, then install with the same chart and helm skips key generation.

We operate Sealed Secrets, key rotation, and the nightly off-cluster key export on managed Kubernetes under Managed Cloud Ops. If your cluster’s secrets are still living in plaintext yaml, scope a hardening pass.