Using External Secrets Operator
Use the External Secrets Operator add-on to set up synchronization with Kubernetes secrets that are stored in the VK Cloud Secret Manager.
- Create a Kubernetes cluster of the latest version, if not done so already.
- Install and configure
kubectl, if not done so already. - Connect to the cluster via
kubectl. - Install the External Secrets Manager add-on, if not done so already.
- Enable API access, if not done so already.
In the VK Cloud Secret Manager, create a secret with the external-secret ID and arbitrary keys.
-
Create the
external-secrets-operatornamespace, if not done so already:kubectl create namespace external-secrets-operator -
Create the
password.yamlmanifest that will store the password to access the VK Cloud Secret Manager:apiVersion: v1kind: Secretmetadata:name: passwordnamespace: external-secrets-operatortype: Opaquedata:password: <PASSWORD>Here,
<PASSWORD>is your password from the VK Cloud management console in the base64 encoding. -
Apply the manifest in the cluster:
kubectl apply -f password.yaml
-
Go to your VK Cloud management console.
-
Click the username in the page header and select Project settings.
-
Go to the API access tab and keep note of the following values:
- Project ID;
- User Domain Name;
- Username.
-
Create the
secretstore.yamlmanifest — an object of theSecretStoretype that describes how to connect to the VK Cloud Secret Manager:apiVersion: external-secrets.io/v1kind: SecretStoremetadata:name: secret-storenamespace: external-secrets-operatorspec:provider:vk:projectID: <PROJECT_ID>url: <AUTH_URL>auth:domain: <USER_DOMAIN_NAME>username: <USERNAME>password:key: passwordname: passwordHere:
<PROJECT_ID>,<USER_DOMAIN_NAME>, and<USERNAME>are the values from the project settings.<AUTH_URL>is an address depending on your region:https://msk.cloud.vk.comfor the Moscow regionhttps://kz.cloud.vk.comfor the Kazakhstan region
-
Apply the manifest in the cluster:
kubectl apply -f secretstore.yaml
-
Create the
externalsecret.yamlmanifest — an object of theExternalSecrettype that describes whatSecretStoreto load the secret from and how to update it:apiVersion: external-secrets.io/v1kind: ExternalSecretmetadata:name: external-secretnamespace: external-secrets-operatorspec:refreshInterval: 5msecretStoreRef:name: secret-storekind: SecretStoretarget:name: external-secretcreationPolicy: Ownerdata:- secretKey: <KEY_NAME_IN_SECRET>remoteRef:key: <SECRET_ID>property: <SECRET_KEY>Здесь:
<KEY_NAME_IN_SECRET>is the name of the key in the Kubernetes secret. Example:password.<SECRET_ID>is the ID of the secret that you created earlier in the VK Cloud Secret Manager.<SECRET_KEY>is the key in the secret from the VK Cloud Secret Manager the value of which you want to synchronize with the Kubernetes secret.
For example, the VK Cloud Secret Manager has a secret with the
external-secretID and the following pairs of values:key1: value1,key2: value2,key3: value3. If you want to set up the Kubernetes secret to synchronize the value ofvalue2, usekey2in thepropertyfield:key: external-secretproperty: key2 -
Apply the manifest in the cluster:
kubectl apply -f externalsecret.yaml
This will create a new object of the Secret type named external-secret in Kubernetes. The add-on will check the value of the specified field of the secret in the VK Cloud Secret Manager every five minutes. If the value changes, the add-on will automatically update it in the Kubernetes secret.
-
Create the
externalsecretall.yamlmanifest that will synchronize all pairs of values from the secret that you created in the VK Cloud Secret Manager:apiVersion: external-secrets.io/v1kind: ExternalSecretmetadata:name: external-secret-allnamespace: external-secrets-operatorspec:refreshInterval: 5msecretStoreRef:name: secret-storekind: SecretStoretarget:name: external-secret-allcreationPolicy: OwnerdataFrom:- extract:key: <SECRET_ID> -
Apply the manifest in the cluster:
kubectl apply -f externalsecretall.yaml
This will create a new object of the Secret type named external-secret-all in Kubernetes. The add-on will check all values of the secret in the VK Cloud Secret Manager every five minutes. If the values change, the add-on will automatically update them in the Kubernetes secret.
-
Verify that the External Secrets Operator add-on correctly synchronizes secrets by using the command:
kubectl -n external-secrets-operator get secretThe command output must have the
external-secretandexternal-secret-allsecrets you created earlier:NAME TYPE DATA AGEexternal-secret Opaque 1 ...external-secret-all Opaque 2 ...external-secrets-webhook Opaque 4 ...password Opaque 1 ... -
View the contents of the secrets:
kubectl -n external-secrets-operator get secret external-secret -o yamlkubectl -n external-secrets-operator get secret external-secret-all -o yaml
A running cluster consumes computing resources and is charged accordingly. If you no longer need the Kubernetes resources you created to test the External Secrets Operator, delete them: