Running YDB in Minikube

To create a YDB cluster using Minikube, follow these steps.

Before you start

  1. Install the Kubernetes CLI kubectl.

  2. Install and run Minikube.

  3. Install the Kubernetes Helm 3 package manager.

  4. Clone the repository with ydb-kubernetes-operator.

    1. git clone https://github.com/ydb-platform/ydb-kubernetes-operator && cd ydb-kubernetes-operator

    Minikube - 图1

Installing a cluster

Install the YDB controller in the cluster

Install YDB in the standard configuration:

CLI

Run the command:

  1. helm upgrade --install ydb-operator deploy/ydb-operator --set metrics.enabled=false

Minikube - 图2

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

Output:

  1. Release "ydb-operator" does not exist. Installing it now.
  2. NAME: ydb-operator
  3. LAST DEPLOYED: Tue Mar 22 08:54:08 2022
  4. NAMESPACE: default
  5. STATUS: deployed
  6. REVISION: 1
  7. TEST SUITE: None

Minikube - 图3

Create a YDB cluster

Apply the manifest for creating a YDB cluster:

CLI

Run the command:

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

Minikube - 图4

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

Minikube - 图5

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.

Create a database

Apply the manifest for creating a database:

CLI

Run the command:

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

Minikube - 图6

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-minikube-sample DNS name. 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. ...
  11. State: Ready
  12. Events:
  13. Type Reason Age From Message
  14. ---- ------ ---- ---- -------
  15. Normal Provisioning 6m32s ydb-operator Resource: *v1.ConfigMap, Namespace: default, Name: database-minikube-sample, changed, result: created
  16. Normal Provisioning 6m32s ydb-operator Resource: *v1.Service, Namespace: default, Name: database-minikube-sample-grpc, changed, result: created
  17. Normal Provisioning 6m32s ydb-operator Resource: *v1.Service, Namespace: default, Name: database-minikube-sample-interconnect, changed, result: created
  18. Normal Provisioning 6m32s ydb-operator Resource: *v1.Service, Namespace: default, Name: database-minikube-sample-status, changed, result: created
  19. Normal Provisioning 6m32s ydb-operator Resource: *v1.StatefulSet, Namespace: default, Name: database-minikube-sample, changed, result: created
  20. Normal Initialized 6m31s ydb-operator Tenant /Root/database-minikube-sample created
  21. Normal ResourcesReady 6m30s ydb-operator Resource are ready and DB is initialized

Minikube - 图7

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-minikube-sample-0 1/1 Running 0 9m33s
    4. storage-minikube-sample-0 1/1 Running 0 11m
    5. ydb-operator-6fc76b5b68-q269l 1/1 Running 0 12m

    Minikube - 图8

  2. Forward port 2135:

    1. kubectl port-forward database-minikube-sample-0 2135

    Minikube - 图9

  3. Install the YDB CLI as described in Installing the YDB CLI.

  4. Query the YDB database:

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

    Minikube - 图10

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

    Output:

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

    Minikube - 图11

    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-minikube-sample

    Minikube - 图12

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

    1. kubectl delete storage.ydb.tech storage-minikube-sample

    Minikube - 图13

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

    1. helm delete ydb-operator

    Minikube - 图14

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