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.

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

Installing a cluster

Install the YDB controller in the cluster

Install YDB in the standard configuration:

Run the command:

helm upgrade --install ydb-operator deploy/ydb-operator --set metrics.enabled=false
  • ydb-operator: The release name.
  • ydb-operator: The name of the chart in the repository you added earlier.

Output:

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

Create a YDB cluster

Apply the manifest for creating a YDB cluster:

Run the command:

kubectl apply -f samples/minikube/storage.yaml

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:

kubectl get storages.ydb.tech
kubectl describe storages.ydb.tech

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:

Run the command:

kubectl apply -f samples/minikube/database.yaml

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:

kubectl describe database.ydb.tech

Name:         database-sample
Namespace:    default
Labels:       <none>
Annotations:  <none>
API Version:  ydb.tech/v1alpha1
Kind:         Database
...
Status:
  ...
  State:  Ready
Events:
  Type    Reason          Age    From          Message
  ----    ------          ----   ----          -------
  Normal  Provisioning    6m32s  ydb-operator  Resource: *v1.ConfigMap, Namespace: default, Name: database-minikube-sample, changed, result: created
  Normal  Provisioning    6m32s  ydb-operator  Resource: *v1.Service, Namespace: default, Name: database-minikube-sample-grpc, changed, result: created
  Normal  Provisioning    6m32s  ydb-operator  Resource: *v1.Service, Namespace: default, Name: database-minikube-sample-interconnect, changed, result: created
  Normal  Provisioning    6m32s  ydb-operator  Resource: *v1.Service, Namespace: default, Name: database-minikube-sample-status, changed, result: created
  Normal  Provisioning    6m32s  ydb-operator  Resource: *v1.StatefulSet, Namespace: default, Name: database-minikube-sample, changed, result: created
  Normal  Initialized     6m31s  ydb-operator  Tenant /Root/database-minikube-sample created
  Normal  ResourcesReady  6m30s  ydb-operator  Resource are ready and DB is initialized

The database is ready to run.

Test the controller

Test how YDB works:

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

    kubectl get pods
    NAME                            READY   STATUS    RESTARTS   AGE
    database-minikube-sample-0      1/1     Running   0          9m33s
    storage-minikube-sample-0       1/1     Running   0          11m
    ydb-operator-6fc76b5b68-q269l   1/1     Running   0          12m      
    
  2. Forward port 2135:

    kubectl port-forward database-minikube-sample-0 2135
    
  3. Install the YDB CLI as described in Installing the YDB CLI.

  4. Query the YDB database:

    ydb \
      --endpoint grpc://localhost:2135 \
      --database /Root/database-minikube-sample \
      table query execute --query 'select 1;'
    
    • --endpoint: Database endpoint.
    • --database: The name of the created database.
    • --query: Query text.

    Output:

    ┌─────────┐
    | column0 |
    ├─────────┤
    | 1       |
    └─────────┘
    

    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:

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

    kubectl delete database.ydb.tech database-minikube-sample
    
  2. To delete a YDB cluster, run the following commands:

    kubectl delete storage.ydb.tech storage-minikube-sample
    
  3. To remove the YDB controller from the Kubernetes cluster, delete the release created by Helm:

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