Create a secret
Store a secret in AWS Secrets Manager and read it into Kubernetes with External Secrets.
This guide stores a secret in AWS Secrets Manager, copies it into a Kubernetes Secret with External Secrets, and passes it to a container as environment variables.
The secret value lives only in AWS Secrets Manager, so it never has to be written into a manifest or a Git repository. You add an ExternalSecret manifest that points to the secret; External Secrets reads it through a ClusterSecretStore, creates the Kubernetes Secret and keeps it up to date when the value in AWS changes.
It is good practice to include the ExternalSecret manifest in your application’s Helm chart, so the Secret is deployed together with the application that uses it.
Prerequisites
Section titled “Prerequisites”This is not a platform API. It needs only the external-secrets module:
| Module | Flag | Default | What it does |
|---|---|---|---|
external-secrets |
global.createClusterSecretStore |
false |
Creates a ClusterSecretStore for AWS Secrets Manager. Set to true. |
external-secrets |
global.enableWriteForClusterSecretStore |
false |
Adds write permissions to the store. By default it can only read secrets. |
aws/kms |
— | — | Recommended, not required. Creates the kms/config key to encrypt secrets with. |
The ClusterSecretStore is named after the external-secrets module name. The examples below use external-secrets, which only works if the module has that name. If your module is named, for example, external-secrets-dev, use external-secrets-dev in secretStoreRef.name.
For the base modules, see Infralib Requirements. A full example is in Infralib Configuration Example at the end of this guide.
1. Create the secret in AWS Secrets Manager
Section titled “1. Create the secret in AWS Secrets Manager”Create the secret in the AWS Console or with the AWS CLI. Encrypt it with the kms/config key created by the Infralib KMS module. For more information, see the AWS Secrets Manager User Guide.
The examples store this data:
EXAMPLE_USERNAME=adminEXAMPLE_PASSWORD=verySecret123With the AWS CLI
Section titled “With the AWS CLI”aws secretsmanager create-secret \ --name example-secret \ --secret-string '{"EXAMPLE_USERNAME":"admin","EXAMPLE_PASSWORD":"verySecret123"}' \ --kms-key-id alias/dev-net-kms/configIn the AWS Console
Section titled “In the AWS Console”-
Open
Secrets Managerand clickStore a new secret. -
Select
Other type of secret, fill in theKey/value pairsand choose thekms/configkey as theEncryption key. ClickNext.
-
Set the
Secret nameand clickNext.
-
Check that the secret exists in AWS Secrets Manager.

You can view and edit existing secrets in the AWS Console:

2. Read the secret into Kubernetes
Section titled “2. Read the secret into Kubernetes”External Secrets reads secrets through a ClusterSecretStore or a SecretStore. List the available stores to find the name to use:
$ kubectl get SecretStores,ClusterSecretStores --all-namespacesNAMESPACE NAME AGE STATUS CAPABILITIES READY clustersecretstore.external-secrets.io/external-secrets 1h Valid ReadWrite TrueCreate an ExternalSecret that copies every key of the AWS secret into a Kubernetes Secret:
apiVersion: external-secrets.io/v1kind: ExternalSecretmetadata: name: example-secret annotations: argocd.argoproj.io/sync-wave: '-2'spec: refreshInterval: 5m dataFrom: - extract: key: example-secret # AWS Secrets Manager secret secretStoreRef: kind: ClusterSecretStore name: external-secrets # the external-secrets module name target: name: example-secret # Kubernetes Secret to create creationPolicy: OwnerFor every field, see the External Secrets documentation.
3. Use the secret in a container
Section titled “3. Use the secret in a container”Load every key of the Secret as an environment variable:
apiVersion: apps/v1kind: Deploymentmetadata: name: nginx labels: app: nginxspec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80 envFrom: - secretRef: name: example-secretFor more information about Secrets in Kubernetes, see Kubernetes documentation.
4. Verify
Section titled “4. Verify”The Kubernetes Secret exists
Section titled “The Kubernetes Secret exists”$ kubectl get secretNAME TYPE DATA AGEexample-secret Opaque 1 10mThe ExternalSecret and the Secret in ArgoCD:

The container has the values
Section titled “The container has the values”
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause / fix |
|---|---|
no matches for kind "ExternalSecret" |
The external-secrets module is not installed. Check the Prerequisites. |
kubectl get ClusterSecretStores returns nothing |
global.createClusterSecretStore is false. Set it to true. |
| The ExternalSecret refers to a store that does not exist | The store is named after the external-secrets module. Use the name shown by kubectl get ClusterSecretStores in secretStoreRef.name. |
| The Kubernetes Secret is not created | kubectl describe externalsecret <name> shows the error under Conditions and Events. Check that dataFrom.extract.key matches the secret name in AWS Secrets Manager. |
| A changed value in AWS does not show up | External Secrets refreshes the Secret every refreshInterval, 5 minutes in the example. |
Infralib Configuration Example
Section titled “Infralib Configuration Example”steps: - name: net type: terraform modules: ... - name: kms source: aws/kms # recommended, provides kms/config ... - name: apps type: argocd-apps modules: ... - name: external-secrets # also the ClusterSecretStore name source: external-secrets inputs: global: createClusterSecretStore: true