Sandboxing on K8s

Sandboxing on Kubernetes allows you to create isolated testing environments without the need to set up a new database or reload data, making it easier to test Vertica features in new versions. Sandboxing enables seamless online upgrades in Kubernetes. While users stay connected to the main cluster, the upgrade is performed on the sandbox. Once the upgrade is complete, the sandbox is promoted to the main cluster. The operator automates the sandboxing process for Vertica subclusters within a custom resource (CR). For more information, see Subcluster sandboxing.

Prerequisites

Sandboxing a Subcluster

The following specification in VerticaDB CR (VerticaDB custom resource definition) has the sandbox information:

Parameter Description
spec.sandboxes[i].name Name of the sandbox.
spec.sandboxes[i].subclusters[i].name Name of the secondary subcluster to be added to the sandbox. The sandbox must include at least one secondary subcluster.
spec.sandboxes[i].image Name of the image to use for the sandbox. If omitted, image from the main cluster will be used. Changing this will force an upgrade for the sandbox where it is defined.

To sandbox a subcluster

  1. Use kubectl edit to open your default text editor and update the YAML file for the specified custom resource. The following command opens a custom resource named vdb for editing:

    $ kubectl edit vdb
    
  2. In the spec section of the custom resource, locate the subclusters subsection and identify the secondary subcluster that you want to sandbox. In the following example, we will sandbox the secondary subcluster, sc2:

    apiVersion: vertica.com/v1
    kind: VerticaDB
    metadata:
     name: vertica-db
    spec:
    ...
     subclusters:
     - affinity: {}
       name: sc1
       resources: {}
       serviceName: sc1
       serviceType: ClusterIP
       size: 3
       type: primary
     - affinity: {}
       name: sc2
       resources: {}
       serviceName: sc2
       serviceType: ClusterIP
       size: 1
       type: secondary
     - affinity: {}
       name: sc3
       resources: {}
       serviceName: sc3
       serviceType: ClusterIP
       size: 1
       type: secondary
    
  3. Now, add an entry for the sandbox. Provide a sandbox name and name of the subcluster(s) that you want to sandbox. For example, we will sandbox subcluster sc2 and name it sandbox1:

    spec:
    ...
     subclusters:
     - affinity: {}
       name: sc1
       resources: {}
       serviceName: sc1
       serviceType: ClusterIP
       size: 3
       type: primary
     - affinity: {}
       name: sc2
       resources: {}
       serviceName: sc2
       serviceType: ClusterIP
       size: 3
       type: secondary
     - affinity: {}
       name: sc3
       resources: {}
       serviceName: sc3
       serviceType: ClusterIP
       size: 3
       type: secondary
     sandboxes:
     - name: sandbox1
       subclusters:
        - name: sc2
    
  4. Save and close the custom resource file. When the update completes, you will receive the following message:

    verticadb.vertica.com/vertica-db edited
    

If you want to include another subcluster in the sandbox, go back to VerticaDB and modify the sandbox information. Following are the contents of the VerticaDB after adding sc3:

spec:
...
  subclusters:
  - affinity: {}
    name: sc1
    resources: {}
    serviceName: sc1
    serviceType: ClusterIP
    size: 3
    type: primary
  - affinity: {}
    name: sc2
    resources: {}
    serviceName: sc2
    serviceType: ClusterIP
    size: 3
    type: secondary
  - affinity: {}
    name: sc3
    resources: {}
    serviceName: sc3
    serviceType: ClusterIP
    size: 3
    type: secondary
  sandboxes:
  - name: sandbox1
	image: opentext/vertica-k8s:24.3.0-0
    subclusters:
      - name: sc2
	  - name: sc3

Checking sandboxing status

You can check the status of sandboxing as follows:

$ kubectl describe vdb
Name:         vertica-db
...
Events:
  Type     Reason                      Age                From                Message
  ----     ------                      ----               ----                -------
  ...
  Normal   SandboxSubclusterStart      8m1s               verticadb-operator  Starting add subcluster "sc2" to sandbox "sandbox1"
  Normal   SandboxSubclusterSucceeded  7m39s              verticadb-operator  Successfully added subcluster "sc2" to sandbox "sandbox1"

You can verify if sandboxing is successful by checking the VerticaDB CR to see if the subcluster type changed from secondary to sandboxprimary.

spec:
...
  subclusters:
  - affinity: {}
    name: sc1
    resources: {}
    serviceName: sc1
    serviceType: ClusterIP
    size: 3
    type: primary
  - affinity: {}
    name: sc2
    resources: {}
    serviceName: sc2
    serviceType: ClusterIP
    size: 3
    type: sandboxprimary
  - affinity: {}
    name: sc3
    resources: {}
    serviceName: sc3
    serviceType: ClusterIP
    size: 3
    type: secondary
  sandboxes:
  - name: sandbox1
	image: opentext/vertica-k8s:24.3.0-0
    subclusters:
      - name: sc2
	  - name: sc3

Alternatively, you can connect to any node in the subcluster using vsql client and query the system table subclusters to check that sandboxing is successful.

$ vsql -h 10.244.2.166 -U dbadmin
Welcome to vsql, the Vertica Analytic Database interactive terminal.

Type:  \h or \? for help with vsql commands
       \g or terminate with semicolon to execute query
       \q to quit

SSL connection (cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, protocol: TLSv1.2)

select distinct subcluster_name, is_primary, sandbox from subclusters where subcluster_name = 'sc2';
 subcluster_name | is_primary | sandbox
-----------------+------------+----------
 sc2             | t          | sandbox1
(1 row)

Upgrading the subcluster

To upgrade the sandbox, simply update the spec.sandboxes.image field.

spec:
...
  sandboxes:
  - image: opentext/vertica-k8s:24.3.0-1
    name: sandbox1
    subclusters:
    - name: sc2
    - name: sc3

Removing Sandboxes

Removing sandboxes allows you to remove a subcluster from the sandbox and return it to the main cluster.

To remove a subcluster from the sandbox, you need to remove the subcluster name from spec.sandboxes.subclusters in VerticaDB. In the following example, subcluster sc3 will be removed from the sandbox:

spec:
...
  sandboxes:
  - image: opentext/vertica-k8s:24.3.0-1
    name: sandbox1
    subclusters:
    - name: sc2

To remove the complete sandbox, remove its information from the VerticaDB:

spec:
...
  sandboxes:[]

Checking unsandboxing status

You can check if the sandbox was removed as follows:

$ kubectl describe vdb
Name:         vertica-db
...
Events:
  Type    Reason                        Age   From                Message
  ----    ------                        ----  ----                -------
  Normal  UnsandboxSubclusterStart      2m3s  verticadb-operator  Starting unsandbox subcluster "sc2"
  Normal  UnsandboxSubclusterSucceeded  111s  verticadb-operator  Successfully unsandboxed subcluster "sc2"
  Normal  UnsandboxSubclusterStart      111s  verticadb-operator  Starting unsandbox subcluster "sc3"
  Normal  UnsandboxSubclusterSucceeded  99s   verticadb-operator  Successfully unsandboxed subcluster "sc3"
  Normal  NodeRestartStarted            90s   verticadb-operator  Starting database restart node of the following pods: vertica-db-sc2-0, vertica-db-sc3-0
  Normal  NodeRestartSucceeded          65s   verticadb-operator  Successfully restarted database nodes and it took 24s

You can verify if the sandbox was removed successfully by opening the VerticaDB CR and checking that subcluster type has changed from sandboxprimary to secondary.

spec:
...
  subclusters:
  - affinity: {}
    name: sc1
    resources: {}
    serviceName: sc1
    serviceType: ClusterIP
    size: 3
    type: primary
  - affinity: {}
    name: sc2
    resources: {}
    serviceName: sc2
    serviceType: ClusterIP
    size: 3
    type: secondary
  - affinity: {}
    name: sc3
    resources: {}
    serviceName: sc3
    serviceType: ClusterIP
    size: 3
    type: secondary

Alternatively, you can connect to any node in the subcluster using the vsql client and query the subclusters system table to verify if unsandboxing was successful.

$ vsql -h 10.244.2.166 -U dbadmin
Welcome to vsql, the Vertica Analytic Database interactive terminal.

Type:  \h or \? for help with vsql commands
       \g or terminate with semicolon to execute query
       \q to quit

SSL connection (cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, protocol: TLSv1.2)

vertdb=> select distinct subcluster_name, is_primary, sandbox from subclusters where subcluster_name = 'sc2';
 subcluster_name | is_primary | sandbox
-----------------+------------+---------
 sc2             | f          |
(1 row)