Use Secrets in a cluster
Keep Kubernetes Secrets in step with {{product}} Secrets through the External Secrets add-on, with no key stored in the cluster.
Replace my-cluster with your cluster's name or id, DB_URL with a secret of yours and shop with a namespace.
The external-secrets add-on runs the External Secrets Operator. Each store in its options
becomes a ClusterSecretStore. An ExternalSecret in the cluster names a secret; the operator
reads it from Deutsche Cloud Secrets, writes a Kubernetes Secret and refreshes it.
- The cluster holds no Deutsche Cloud credential. The operator proves itself with its service-account token, and Deutsche Cloud answers only for the secrets the store lists.
- A store lists secret names (
DB_URL) or name prefixes (PAYMENTS_*); never every secret. - With
environment, a name means that environment's secret, else the shared one. Without it, shared secrets only. - With
namespaces, only ExternalSecrets in those namespaces may use the store. - Every read is in the secret's access log, with the cluster as the reader, and in the audit log
as
secrets:GetSecretValue.
Prerequisites
- Permission for
eks:CreateAddonon the cluster. In the console, alsoeks:DescribeClusterto open the cluster. secrets:GetSecretValueon every secret a store names, or on every secret (secret/*) for aPREFIX_*entry: a prefix also reaches secrets created later.
Install the add-on
- Open Kubernetes, open the cluster, then choose Add-ons.
- Choose Add an add-on, then External Secrets.
- Name the store, list its secrets, and choose an environment and namespaces if you want.
- Choose Install.
dcloud eks addons create my-cluster --name external-secrets --config 'stores=[{"name":"ews","secrets":["DB_URL","PAYMENTS_*"],"environment":"prod","namespaces":["shop"]}]'POST /eks/api/clusters/my-cluster/addons
{ "name": "external-secrets", "config": { "stores": [{ "name": "ews", "secrets": ["DB_URL", "PAYMENTS_*"], "environment": "prod", "namespaces": ["shop"] }] } }resource "dcloud_eks_addon" "external_secrets" {
cluster_id = dcloud_eks_cluster.main.id
name = "external-secrets"
config = jsonencode({
stores = [{ name = "ews", secrets = ["DB_URL", "PAYMENTS_*"], environment = "prod" }]
})
}Sync a secret into a namespace
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: db
namespace: shop
spec:
refreshInterval: 1h
secretStoreRef: { kind: ClusterSecretStore, name: ews }
target: { name: db }
data:
- secretKey: url
remoteRef: { key: DB_URL }kubectl get secret db -n shop shows the Secret once the operator has read it. A secret whose
value is JSON can be split into keys with dataFrom: [{ extract: { key: NAME } }].
Keep refreshInterval at an hour or more unless a value changes often: each refresh is a read in
the secret's access log. A store answers at most 600 reads a minute per cluster.
Change or remove
Changing the stores (Change in the console, dcloud eks addons update) needs
secrets:GetSecretValue on what the new stores name. Removing the add-on deletes the operator and
the stores; the Kubernetes Secrets it wrote stay until you delete them.