# Cluster Operations

This page describes the steps to perform the following operations using the TigerGraph Kubernetes Operator.

In Kubernetes, you provision resources such as TigerGraph clusters by creating a Deployment. Depending on the context, this document may refer to creating a cluster by creating a Deployment.

## Create TigerGraph clusters

To create a TigerGraph cluster, run the following command:

``$kubectl tg create --cluster-name <cluster_name> --storage-class <storage_class> --namespace <namespace_name>`` Each cluster is provisioned with persistent volumes for each node by default. When you create a cluster with persistent volumes, you must specify a storage class. If you create a cluster in a specific namespace, the namespace must already exist. The command does not create a namespace for you. If you have cloned TigerGraph images for a self-hosted registry, specify the registry with the `--docker-registry` option: ``$ kubectl tg create --cluster-name <cluster_name> --namespace <namespace_name> --docker-registry <your_registry>``

If your registry is private, you also need to provide a Secret that allows you to access to the private registry. Make sure the Secret exists in the same namespace as the one where you are creating the cluster.

You can specify pod CPU, memory, and TigerGraph version etc. through command-line options. Run `kubectl tg help` to view all options available. If you do not specify the options, the command uses the default values for each of the options. You can view the default values for each options in the help text as well.

 The `--ha` flag specifies the replication factor (HA factor) of the cluster, which is the total number of instances of your data. If you create a 6-node cluster with the `--ha 2` flag, your cluster has two instances of data that are divided int 3 partitions.

## List TigerGraph clusters

Run the following command to list all running TigerGraph clusters in all namespaces as well as their size:

## Delete TigerGraph clusters

Run the following command to delete a cluster. Replace `<cluster_name>` with the name of the cluster, and `<namespace_name>` with the namespace where the cluster is provisioned:

``$kubectl tg delete --cluster-name <cluster_name> --namespace <namespace_name>`` To protect your data, deleting a cluster does not delete the Persistent Volume Claims (PVC) provisioned when you create the cluster. To delete the PVCs created with a cluster, run the following command: ``$ kubectl delete pvc  -l app=<cluster_name> -n <namespace_name>``

## Shrink or expand a cluster

Run the following commands to change the size of a cluster. Replace `<cluster_name>` with the name of the cluster, and `<namespace_name>` with the namespace where the cluster is provisioned:

``\$ kubectl tg update --cluster-name <cluster_name> --size <size> --ha <ha_factor> --namespace <namespace_name>``

The `--ha` flag to change the High Availability factor is optional.

 After shrinking a cluster, delete the PVC of the pods which were deleted. Otherwise, executing the expand command in the future will cause an error for the remaining data on the PVC.

Running `kubectl tg update` automatically creates a backup of the cluster CR before the update. If the update fails, delete the failed cluster, then create it again from the backup file.

``kubectl apply -f <path_to_cluster_backup> --namespace <namespace_name>``

Remember that an expansion operation creates new pods, so in the case of a failed expansion, the newly created pods should be manually removed.

For example, if expanding from a cluster size of 5 to 6 results in a failed expansion, delete cluster number `5` (cluster numbering begins with `0`).

Run `kubectl get pvc -l app=<app_name> --namespace <namespace_name>` to list all PVCs and double-check their age. The newest PVC is the one to delete.