Skip to navigation

Kubernetes with External Secrets

External Secrets Operator (ESO) runs in your Kubernetes cluster, signs in to Secret Manager with an app credential, and copies secrets into ordinary Kubernetes Secrets that your pods use. It reads Secret Manager through ESO’s Vault provider (KV version 2), so no IBEE-specific software is needed. This works with any Kubernetes cluster that can reach your workspace’s address.

How it works

  1. You store the app credential’s Secret ID in a Kubernetes Secret.
  2. A SecretStore tells ESO the address, namespace and Role ID.
  3. Each ExternalSecret names a secret in Secret Manager (for example payments/db) and the Kubernetes Secret to create.
  4. ESO reads it and creates the Kubernetes Secret, then reads it again at every refresh interval. Each read is a billed operation.

Before you begin

  • A cluster, kubectl and helm.
  • An app credential, preferably Read only and limited to the application’s folder (for example payments), with its Role ID and Secret ID. See Create an app credential.
  • Your workspace’s address and namespace from Secret Manager → Connect.

Steps

1

Install External Secrets Operator

Skip this if ESO is already installed.

helm repo add external-secrets https://charts.external-secrets.io
helm upgrade --install external-secrets external-secrets/external-secrets \
--namespace external-secrets --create-namespace

The examples use the external-secrets.io/v1 API. Check that your ESO version serves it:

kubectl api-resources --api-group=external-secrets.io
2

Store the Secret ID in the cluster

Create the Secret in the namespace where your application runs (here example-app):

kubectl create secret generic ibee-app-credential \
--namespace example-app \
--from-literal=secret-id="$SECRET_ID"
3

Create a SecretStore

secretstore.yaml
apiVersion: external-secrets.io/v1
kind: SecretStore
metadata:
name: ibee-secret-manager
namespace: example-app
spec:
provider:
vault:
server: https://secrets.ibee.ai # your address from Connect
namespace: acme-payments # your namespace
path: secret
version: v2
auth:
appRole:
path: approle
roleId: <role ID of the app credential>
secretRef:
name: ibee-app-credential
key: secret-id
kubectl apply -f secretstore.yaml
4

Create an ExternalSecret

This copies every key of payments/db into a Kubernetes Secret named payments-db:

externalsecret.yaml
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: payments-db
namespace: example-app
spec:
refreshInterval: 1h
secretStoreRef:
name: ibee-secret-manager
kind: SecretStore
target:
name: payments-db
creationPolicy: Owner
dataFrom:
- extract:
key: payments/db
kubectl apply -f externalsecret.yaml

To copy only some keys, use data instead of dataFrom:

data:
- secretKey: DB_PASSWORD # key in the Kubernetes Secret
remoteRef:
key: payments/db # path in Secret Manager
property: password # key inside the secret
5

Use it in a pod

containers:
- name: app
image: registry.example.com/payments-api:1.4.2
envFrom:
- secretRef:
name: payments-db

Verify it worked

kubectl get secretstore ibee-secret-manager -n example-app # STATUS Valid, READY True
kubectl get externalsecret payments-db -n example-app # STATUS SecretSynced, READY True
kubectl get secret payments-db -n example-app -o jsonpath='{.data}' | jq 'keys'

Read IBEE-managed secrets

Credentials that IBEE products create live in the read-only ibee-managed/ store. Add a second SecretStore with path: ibee-managed and reference it from the ExternalSecret. Only a credential without a folder can read ibee-managed/.

apiVersion: external-secrets.io/v1
kind: SecretStore
metadata:
name: ibee-secret-manager-managed
namespace: example-app
spec:
provider:
vault:
server: https://secrets.ibee.ai
namespace: acme-payments
path: ibee-managed
version: v2
auth:
appRole:
path: approle
roleId: <role ID of the app credential>
secretRef:
name: ibee-app-credential
key: secret-id

TLS certificates and registry logins

Use a template to create a Kubernetes Secret of a specific type.

A TLS secret, from a secret in Secret Manager with the keys tls.crt and tls.key:

target:
name: shop-tls
template:
type: kubernetes.io/tls
dataFrom:
- extract:
key: shop/tls

A registry pull secret, from a secret with the keys registry, username and password:

target:
name: registry-pull
template:
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: '{"auths":{"{{ .registry }}":{"username":"{{ .username }}","password":"{{ .password }}"}}}'
dataFrom:
- extract:
key: ci/registry

Choose a refresh interval

ESO reads each secret again at every refreshInterval. Each read is a billed operation (₹4 per 10,000), so a short interval costs more and gives little: most applications only pick up a new value when their pods restart.

refreshIntervalReads per secret per monthCost per secret per month
1m43,200₹17.28
5m8,640₹3.46
1h (recommended)720₹0.29
24h30₹0.01
  • dataFrom.extract reads the whole secret once. Several data entries that point at the same secret may each be read separately.

  • To pick up a change at once, without waiting for the interval:

    kubectl annotate externalsecret payments-db -n example-app force-sync=$(date +%s) --overwrite
  • Values loaded with envFrom or env change only when the pod restarts. Secrets mounted as volumes update in place. Tools such as Stakater Reloader can restart a Deployment when its Secret changes.

Shared clusters

A ClusterSecretStore lets every namespace in the cluster read everything its app credential can read. When several teams or applications share a cluster, give each Kubernetes namespace its own SecretStore with its own app credential, limited to that application’s folder.

Troubleshooting

Start with kubectl describe externalsecret <name> -n <namespace> and kubectl describe secretstore <name> -n <namespace>.

You seeWhat it meansWhat to do
SecretStore not ready, with a 400 on login about the role or secret IDWrong Role ID or Secret ID, or the Secret ID was replacedIssue a new Secret ID and update ibee-app-credential
permission deniedThe credential’s folder doesn’t include the path, or it’s folder-limited and reads ibee-managed/Use a credential for that folder, or one without a folder
namespace not found, or a 404namespace: is wrong or missingCopy it from Connect
429 in ESO logsToo many reads from the cluster’s IP addressRaise refreshInterval
The Kubernetes Secret updated but the app still has the old valueThe app reads it as environment variablesRestart the pods, or mount the Secret as a volume
no matches for kind "ExternalSecret" in version "external-secrets.io/v1"Your ESO version doesn’t serve the v1 APIUpgrade ESO