Using TiKV Operator

Get started using TiKV Operator

This document explains how to deploy a basic TiKV Cluster using TiKV Operator. TiKV Operator is a Kubernetes Operator that aims to automate the deployment, management, and operational tasks of TiKV clusters.

Step 1: Create a Kubernetes cluster

If you have already created a Kubernetes cluster, skip to Step 2: Deploy TiKV Operator.

This section covers 2 different ways to create a simple Kubernetes cluster that can be used to test TiKV locally. Choose whichever that best matches your environment or experience level.

  • Using kind (Kubernetes in Docker)
  • Using minikube (Kubernetes running locally in a VM)

You can refer to their official documents to prepare a Kubernetes cluster.

The following shows a simple way to create a Kubernetes cluster using kind. Make sure Docker is up and running before proceeding.

  • On macOS / Linux:

    curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.8.1/kind-$(uname)-amd64
    chmod +x ./kind
    ./kind create cluster
    
  • On Windows:

    curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.8.1/kind-windows-amd64
    .\kind-windows-amd64.exe create cluster
    

Step 2: Deploy TiKV Operator

Before deployment, make sure the following requirements are satisfied:

  • A running Kubernetes Cluster that kubectl can connect to
  • Helm 3
  1. Install helm

    curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
    

    Refer to Helm Documentation for more installation alternatives.

  2. Install CRD

    kubectl apply -f https://raw.githubusercontent.com/tikv/tikv-operator/master/manifests/crd.v1beta1.yaml
    
  3. Install tikv-operator, following the steps below:

    a. Add the PingCAP Repository:

    helm repo add pingcap https://charts.pingcap.org/
    

    b. Create a namespace for TiKV Operator:

    kubectl create ns tikv-operator
    

    c. Install TiKV Operator:

    helm install --namespace tikv-operator tikv-operator pingcap/tikv-operator --version v0.1.0
    

    d. Confirm that the TiKV Operator components are running:

    kubectl --namespace tikv-operator get pods
    

Step 3: Deploy TiKV Cluster

  1. Deploy the TiKV Cluster:

    curl -LO https://raw.githubusercontent.com/tikv/tikv-operator/master/examples/basic/tikv-cluster.yaml
    kubectl apply -f tikv-cluster.yaml
    

    Expected output:

    tikvcluster.tikv.org/basic created
    
  2. Wait for the cluster to be ready:

    kubectl wait --for=condition=Ready --timeout 10m tikvcluster/basic
    

    It may takes several minutes as it needs to pull images from Docker Hub.

  3. Check the progress with the following command:

    kubect get pods -o wide
    

    Note:

    If the network connection to the Docker Hub is slow, you can try this example which uses images hosted in Alibaba Cloud:

    curl -LO https://raw.githubusercontent.com/tikv/tikv-operator/master/examples/basic-cn/tikv-cluster.yaml
    kubectl apply -f tikv-cluster.yaml
    

Step 4: Access the PD endpoint

Open a new terminal tab and run this command:

kubectl port-forward svc/basic-pd 2379:2379

This will forward local port 2379 to PD service basic-pd.

Now, you can access the PD endpoint with pd-ctl or any other PD client:

$ pd-ctl cluster
{
  "id": 6841476120821315702,
  "max_peer_count": 3
}