Deploying YDB in AWS EKS

To use Kubernetes to create a cluster YDB, follow the steps below.

Before you start

  1. Configure awscli and eksctl to work with AWS resources according to the documentation.

  2. Install the Kubernetes CLI kubectl.

  3. Create a Kubernetes cluster.

    You can use an existing Kubernetes cluster or create a new one.

    Warning

    Make sure that you’re using Kubernetes version 1.20 or higher.

    How to create Kubernetes cluster

    CLI

    1. eksctl create cluster \
    2. --name yandex-database \
    3. --nodegroup-name standard-workers \
    4. --node-type c5a.2xlarge \
    5. --nodes 3 \
    6. --nodes-min 1 \
    7. --nodes-max 4

    Deploying in AWS Elastic Kubernetes Service - 图1

    A Kubernetes cluster named yandex-database is created. The --node-type flag indicates that the cluster is deployed using c5a.2xlarge (8vCPUs, 16 GiB RAM) instances. This meets our guidelines for running YDB.

    It takes 10 to 15 minutes on average to create a cluster. Wait for the process to complete before proceeding to the next step of YDB deployment. The kubectl configuration will be automatically updated to work with the cluster after it is created.

  4. Install the Kubernetes Helm 3 package manager.

  5. Add a repository for Yandex.Cloud to Helm:

    CLI

    Run the command:

    1. helm repo add ydb https://charts.ydb.tech/

    Deploying in AWS Elastic Kubernetes Service - 图2

    • ydb: The repository alias.
    • https://charts.ydb.tech/: The repository URL.

    Output:

    1. "ydb" has been added to your repositories

    Deploying in AWS Elastic Kubernetes Service - 图3

  6. Update the Helm chart index:

    CLI

    Run the command:

    1. helm repo update

    Deploying in AWS Elastic Kubernetes Service - 图4

    Output:

    1. Hang tight while we grab the latest from your chart repositories...
    2. ...Successfully got an update from the "ydb" chart repository
    3. Update Complete. Happy Helming!⎈

    Deploying in AWS Elastic Kubernetes Service - 图5

Install the YDB controller in the cluster

Install YDB in the standard configuration:

CLI

Run the command:

  1. helm install ydb-operator ydb/operator

Deploying in AWS Elastic Kubernetes Service - 图6

  • ydb-operator: The release name.
  • ydb/operator: The name of the chart in the repository you added earlier.

Output:

  1. NAME: ydb-operator
  2. LAST DEPLOYED: Thu Aug 12 19:32:28 2021
  3. NAMESPACE: default
  4. STATUS: deployed
  5. REVISION: 1
  6. TEST SUITE: None

Deploying in AWS Elastic Kubernetes Service - 图7

Create a YDB cluster

Apply the manifest for creating a YDB cluster:

CLI

Run the command:

  1. kubectl apply -f samples/storage.yaml

Deploying in AWS Elastic Kubernetes Service - 图8

This command creates a StatefulSet object that describes a set of containers with stable network IDs and disks assigned to them, as well as Service and ConfigMap objects that are required for the cluster to work.

You can check the progress of YDB cluster creation using the following commands:

  1. kubectl get storages.ydb.tech
  2. kubectl describe storages.ydb.tech

Deploying in AWS Elastic Kubernetes Service - 图9

Wait until the status of the Storage resource changes to Ready.

Warning

The cluster configuration is static. The controller won’t process any changes when the manifest is reapplied. You can only update cluster parameters such as version or disk size by creating a new cluster.

The standard configuration includes the minimum required 9 storage nodes, 80 GB each. We recommend using disks of at least 80 GB to ensure the stable operation of YDB clusters.

Create a database

Apply the manifest for creating a database:

CLI

Run the command:

  1. kubectl apply -f samples/minikube/database.yaml

Deploying in AWS Elastic Kubernetes Service - 图10

Note

The .spec.storageClusterRef.name key value must match the name of the storage resource of the cluster part.

After processing the manifest, a StatefulSet object that describes a set of dynamic nodes is created. The created database will be accessible from inside the Kubernetes cluster by the database-sample DNS name or the database-sample.<namespace>.svc.cluster.local FQDN, where namespace indicates the namespace that the release was installed in. The database is connected to through port 2135.

View the status of the created resource:

  1. kubectl describe database.ydb.tech
  2. Name: database-sample
  3. Namespace: default
  4. Labels: <none>
  5. Annotations: <none>
  6. API Version: ydb.tech/v1alpha1
  7. Kind: Database
  8. ...
  9. Status:
  10. State: Ready
  11. Events:
  12. Type Reason Age From Message
  13. ---- ------ ---- ---- -------
  14. Normal Provisioning 8m10s ydb-operator Resource sync is in progress
  15. Normal Provisioning 8m9s ydb-operator Resource sync complete
  16. Normal TenantInitialized 8m9s ydb-operator Tenant /root/database-sample created

Deploying in AWS Elastic Kubernetes Service - 图11

The database is ready to run.

Test the controller

Test how YDB works:

CLI

  1. Check that all nodes are in the Ready status:

    1. kubectl get pods
    2. NAME READY STATUS RESTARTS AGE
    3. database-sample-0 1/1 Running 0 1m
    4. database-sample-1 1/1 Running 0 1m
    5. database-sample-2 1/1 Running 0 1m
    6. database-sample-3 1/1 Running 0 1m
    7. database-sample-4 1/1 Running 0 1m
    8. database-sample-5 1/1 Running 0 1m
    9. storage-sample-0 1/1 Running 0 1m
    10. storage-sample-1 1/1 Running 0 1m
    11. storage-sample-2 1/1 Running 0 1m
    12. storage-sample-3 1/1 Running 0 1m
    13. storage-sample-4 1/1 Running 0 1m
    14. storage-sample-5 1/1 Running 0 1m
    15. storage-sample-6 1/1 Running 0 1m
    16. storage-sample-7 1/1 Running 0 1m
    17. storage-sample-8 1/1 Running 0 1m

    Deploying in AWS Elastic Kubernetes Service - 图12

  2. Start a new pod using the YDB CLI:

    1. kubectl run -it --image=cr.yandex/yc/ydb:21.4.30 --rm ydb-cli bash

    Deploying in AWS Elastic Kubernetes Service - 图13

  3. Query the YDB database:

    1. ydb \
    2. --endpoint grpc://database-sample:2135 \
    3. --database /root/database-sample \
    4. table query execute --query 'select 1;'

    Deploying in AWS Elastic Kubernetes Service - 图14

    • --endpoint: Database endpoint.
    • --database: The name of the created database.
    • --query: Query text.

    Output:

    1. ┌─────────┐
    2. | column0 |
    3. ├─────────┤
    4. | 1 |
    5. └─────────┘

    Deploying in AWS Elastic Kubernetes Service - 图15

    For more on YDB CLI commands, see the documentation.

Release the resources you don’t use

If you no longer need the created resources, delete them:

CLI

  1. To delete a YDB database, just delete the Database resource mapped to it:

    1. kubectl delete database.ydb.tech database-sample

    Deploying in AWS Elastic Kubernetes Service - 图16

  2. To delete a YDB cluster, run the following commands:

    1. kubectl delete storage.ydb.tech storage-sample
    2. kubectl delete pvc -l app.kubernetes.io/name=ydb

    Deploying in AWS Elastic Kubernetes Service - 图17

  3. To remove the YDB controller from the Kubernetes cluster, delete the release created by Helm:

    1. helm delete ydb-operator

    Deploying in AWS Elastic Kubernetes Service - 图18

    • ydb-operator: The name of the release that the controller was installed under.