Syncing with Yandex Managed Service for Kubernetes secrets
External Secrets Operator
There are various options for integrating
To set up secret syncing:
- Install External Secrets Operator and set up Yandex Lockbox.
- Configure your Managed Service for Kubernetes cluster.
- Create an External Secret.
If you no longer need the resources you created, delete them.
You can also use a ready-made configuration file to deploy the infrastructure for syncing Yandex Lockbox secrets with Managed Service for Kubernetes cluster secrets via Terraform. For more information, see Create the infrastructure on the Terraform tab.
Getting started
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. If you do not have a billing account, create one and link a cloud to it.
If you have an active billing account, you can create or select a folder for your infrastructure on the cloud page
Learn more about clouds and folders here.
Required paid resources
The cost of resources for syncing secrets includes:
- Fee for using a Managed Service for Kubernetes master (see Managed Service for Kubernetes pricing).
- Fee for Managed Service for Kubernetes node group's computing resources and disks (see Yandex Compute Cloud pricing).
Create the infrastructure
-
If you do not have a network yet, create one.
-
If you do not have any subnets yet, create them in the availability zones where the new Managed Service for Kubernetes cluster and node group will reside.
-
Create these service accounts:
- Service account for Kubernetes resources with the
k8s.clusters.agentandvpc.publicAdminroles for the folder where the Managed Service for Kubernetes cluster is being created. - Service account for Managed Service for Kubernetes nodes with the container-registry.images.puller role for the folder containing the Docker image registry. Managed Service for Kubernetes nodes will use this account to pull the required Docker images from the registry.
Tip
You can use the same service account for all operations.
- Service account for Kubernetes resources with the
-
Create security groups for the Managed Service for Kubernetes cluster and its node groups.
Warning
The configuration of security groups determines performance and availability of the cluster and the services and applications running in it.
-
Create a Managed Service for Kubernetes cluster and node group. When creating a Managed Service for Kubernetes cluster, specify the previously created service accounts for resources and nodes, as well as the security groups.
-
Create a Yandex Lockbox secret with the following properties:
- Name:
lockbox-secret. - Key: Enter
passwordas the non-secret ID. - Value: Enter the confidential data for storing
p@$$w0rd.
Save the secret ID, as you will need it later.
- Name:
-
If you do not have Terraform yet, install it.
-
Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.
-
Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it
. -
Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.
-
Download the k8s-cluster-and-lockbox.tf
configuration file of the Managed Service for Kubernetes cluster to the same working directory.This file describes:
-
Yandex Lockbox secret.
-
Managed Service for Kubernetes cluster.
-
Service account for Managed Service for Kubernetes resources and nodes.
-
Security groups which contain rules required for the Managed Service for Kubernetes cluster and its node groups.
Warning
The configuration of security groups determines performance and availability of the cluster and the services and applications running in it.
-
Specify the following in the configuration file:
- Folder ID.
- Kubernetes version for the Managed Service for Kubernetes cluster and node groups.
- Name of the service account for Managed Service for Kubernetes resources and nodes.
-
Validate your Terraform configuration files using this command:
terraform validateTerraform will display any configuration errors detected in your files.
-
Create the required infrastructure:
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console
. -
-
Save the ID of the created secret displayed in the terminal. You will need it later.
Set up your environment
-
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the
yc config set folder-id <folder_ID>command. You can also specify a different folder for any command using--folder-nameor--folder-id. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions. -
Install
jq:sudo apt update && sudo apt install jq -
Install kubectl
and configure it to work with the new cluster.
Install External Secrets Operator and set up Yandex Lockbox
- Follow this guide to install the External Secrets Operator.
- Assign the service account you created when installing External Secrets Operator the
lockbox.payloadViewerrole for the previously createdlockbox-secret.
Configure your Managed Service for Kubernetes cluster
-
Create a
nsnamespace to store External Secrets Operator objects in:kubectl create namespace ns -
Create a
yc-authsecret with thesa-key.jsonkey you created when installing the External Secrets Operator:kubectl --namespace ns create secret generic yc-auth \ --from-file=authorized-key=sa-key.json -
Create a SecretStore
containing theyc-authsecret:kubectl --namespace ns apply -f - <<< ' apiVersion: external-secrets.io/v1beta1 kind: SecretStore metadata: name: secret-store spec: provider: yandexlockbox: auth: authorizedKeySecretRef: name: yc-auth key: authorized-key'
Create an External Secret
-
Create an ExternalSecret
object pointing tolockbox-secretinsecret-store:kubectl --namespace ns apply -f - <<< ' apiVersion: external-secrets.io/v1beta1 kind: ExternalSecret metadata: name: external-secret spec: refreshInterval: 1h secretStoreRef: name: secret-store kind: SecretStore target: name: k8s-secret data: - secretKey: password remoteRef: key: <secret_ID> property: password'Where:
key: ID of the Yandex Lockbox secret you created, i.e.,lockbox-secret.spec.target.name: New key name,k8s-secret. External Secrets Operator will create this key and place thelockbox-secretparameters in it.
-
Make sure the new
k8s-secretkey contains thelockbox-secretvalue:kubectl --namespace ns get secret k8s-secret \ --output=json | \ jq --raw-output '."data"."password"' | \ base64 --decodeThe command returns the
passwordkey value fromlockbox-secret:p@$$w0rd
Delete the resources you created
Delete the resources you no longer need to avoid paying for them:
- Delete the Managed Service for Kubernetes cluster.
- Delete the public static IP address for your Managed Service for Kubernetes cluster if you reserved one.
- Delete
lockbox-secret.
-
In the terminal window, go to the directory containing the infrastructure plan.
Warning
Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.
-
Delete resources:
-
Run this command:
terraform destroy -
Confirm deleting the resources and wait for the operation to complete.
All the resources described in the Terraform manifests will be deleted.
-