Deploy a Heterogeneous Cluster for an Existing TiDB Cluster

This document describes how to deploy a heterogeneous cluster for an existing TiDB cluster. A heterogeneous cluster consists of nodes with different configurations from the existing TiDB cluster.

Usage scenarios

This document is applicable to scenarios in which you need to create differentiated instances for an existing TiDB cluster, such as the following:

  • Create TiKV clusters with different configurations and different labels for hotspot scheduling.
  • Create TiDB clusters with different configurations for OLTP and OLAP queries.

Prerequisites

You already have a TiDB cluster. If not, deploy a TiDB cluster in Kubernetes first.

Deploy a heterogeneous cluster

Depending on whether you need to enable Transport Layer Security (TLS) for a heterogeneous cluster, choose one of the following methods:

  • Deploy a heterogeneous cluster
  • Deploy a TLS-enabled heterogeneous cluster

  • non-TLS

  • TLS

Deploy a heterogeneous cluster

To deploy a heterogeneous cluster, do the following:

  1. Create a cluster configuration file for the heterogeneous cluster.

    For example, save the following configuration as the cluster.yaml file. Replace ${heterogeneous_cluster_name} with the desired name of your heterogeneous cluster, and replace ${origin_cluster_name} with the name of the existing cluster.

    Note:

    Comparing with the the configuration file of a normal TiDB cluster, the only difference in the configuration file of a heterogeneous TiDB cluster is that you need to additionally specify the spec.cluster.name field as the name of an existing TiDB cluster. According to this field, TiDB Operator adds the heterogeneous cluster to the existing TiDB cluster.

    1. apiVersion: pingcap.com/v1alpha1
    2. kind: TidbCluster
    3. metadata:
    4. name: ${heterogeneous_cluster_name}
    5. spec:
    6. configUpdateStrategy: RollingUpdate
    7. version: v5.4.0
    8. timezone: UTC
    9. pvReclaimPolicy: Delete
    10. discovery: {}
    11. cluster:
    12. name: ${origin_cluster_name}
    13. tikv:
    14. baseImage: pingcap/tikv
    15. maxFailoverCount: 0
    16. replicas: 1
    17. # If storageClassName is not set, the default Storage Class of the Kubernetes cluster is used.
    18. # storageClassName: local-storage
    19. requests:
    20. storage: "100Gi"
    21. config: {}
    22. tidb:
    23. baseImage: pingcap/tidb
    24. maxFailoverCount: 0
    25. replicas: 1
    26. service:
    27. type: ClusterIP
    28. config: {}
    29. tiflash:
    30. baseImage: pingcap/tiflash
    31. maxFailoverCount: 0
    32. replicas: 1
    33. storageClaims:
    34. - resources:
    35. requests:
    36. storage: 100Gi

    For more configurations and field meanings of TiDB cluster, see the TiDB cluster configuration document.

  2. In the configuration file of your heterogeneous cluster, modify the configurations of each node according to your need.

    For example, you can modify the number of replicas for each component in the cluster.yaml file, or remove components that are not needed.

  3. Create the heterogeneous cluster by running the following command. You need to replace cluster.yaml with the configuration filename of your heterogeneous cluster.

    1. kubectl create -f cluster.yaml -n ${namespace}

    If the output shows tidbcluster.pingcap.com/${heterogeneous_cluster_name} created, the execution is successful. Then, TiDB Operator will create the TiDB cluster with the configurations according to the cluster configuration file.

Deploy a TLS-enabled heterogeneous cluster

To enable TLS for a heterogeneous cluster, you need to explicitly declare the TLS configuration, issue the certificates using the same certification authority (CA) as the target cluster and create new secrets with the certificates.

If you want to issue the certificate using cert-manager, choose the same Issuer as that of the target cluster to create your Certificate.

For detailed procedures to create certificates for the heterogeneous cluster, refer to the following two documents:

After creating certificates, take the following steps to deploy a TLS-enabled heterogeneous cluster.

  1. Create a cluster configuration file for the heterogeneous cluster.

    For example, save the following configuration as the cluster.yaml file. Replace ${heterogeneous_cluster_name} with the desired name of your heterogeneous cluster, and replace ${origin_cluster_name} with the name of the existing cluster.

    Note:

    Comparing with the the configuration file of a normal TiDB cluster, the only difference in the configuration file of a heterogeneous TiDB cluster is that you need to additionally specify the spec.cluster.name field as the name of an existing TiDB cluster. According to this field, TiDB Operator adds the heterogeneous cluster to the existing TiDB cluster.

    1. apiVersion: pingcap.com/v1alpha1
    2. kind: TidbCluster
    3. metadata:
    4. name: ${heterogeneous_cluster_name}
    5. spec:
    6. tlsCluster:
    7. enabled: true
    8. configUpdateStrategy: RollingUpdate
    9. version: v5.4.0
    10. timezone: UTC
    11. pvReclaimPolicy: Delete
    12. discovery: {}
    13. cluster:
    14. name: ${origin_cluster_name}
    15. tikv:
    16. baseImage: pingcap/tikv
    17. maxFailoverCount: 0
    18. replicas: 1
    19. # If storageClassName is not set, the default Storage Class of the Kubernetes cluster is used.
    20. # storageClassName: local-storage
    21. requests:
    22. storage: "100Gi"
    23. config: {}
    24. tidb:
    25. baseImage: pingcap/tidb
    26. maxFailoverCount: 0
    27. replicas: 1
    28. service:
    29. type: ClusterIP
    30. config: {}
    31. tlsClient:
    32. enabled: true
    33. tiflash:
    34. baseImage: pingcap/tiflash
    35. maxFailoverCount: 0
    36. replicas: 1
    37. storageClaims:
    38. - resources:
    39. requests:
    40. storage: 100Gi

    In the configuration file, spec.tlsCluster.enabledcontrols whether to enable TLS between the components and spec.tidb.tlsClient.enabledcontrols whether to enable TLS for the MySQL client.

  2. In the configuration file of your heterogeneous cluster, modify the configurations of each node according to your need.

    For example, you can modify the number of replicas for each component in the cluster.yaml file, or remove components that are not needed.

  3. Create the TLS-enabled heterogeneous cluster by running the following command. You need to replace cluster.yaml with the configuration filename of the heterogeneous cluster.

    1. kubectl create -f cluster.yaml -n ${namespace}

    If the output shows tidbcluster.pingcap.com/${heterogeneous_cluster_name} created, the execution is successful. Then, TiDB Operator will create the TiDB cluster with the configurations according to your cluster configuration file.

Deploy a cluster monitoring component

If you need to deploy a monitoring component for a heterogeneous cluster, take the following steps to add the heterogeneous cluster name to the TidbMonitor CR file of an existing TiDB cluster.

  1. Edit the TidbMonitor Custom Resource (CR) of the existing TiDB cluster:

    1. kubectl edit tm ${cluster_name} -n ${namespace}
  2. Replace ${heterogeneous_cluster_name} with the desired name of your heterogeneous cluster, and replace ${origin_cluster_name} with the name of the existing cluster. For example:

    1. apiVersion: pingcap.com/v1alpha1
    2. kind: TidbMonitor
    3. metadata:
    4. name: heterogeneous
    5. spec:
    6. clusters:
    7. - name: ${origin_cluster_name}
    8. - name: ${heterogeneous_cluster_name}
    9. prometheus:
    10. baseImage: prom/prometheus
    11. version: v2.27.1
    12. grafana:
    13. baseImage: grafana/grafana
    14. version: 7.5.11
    15. initializer:
    16. baseImage: pingcap/tidb-monitor-initializer
    17. version: v5.4.0
    18. reloader:
    19. baseImage: pingcap/tidb-monitor-reloader
    20. version: v1.0.1
    21. prometheusReloader:
    22. baseImage: quay.io/prometheus-operator/prometheus-config-reloader
    23. version: v0.49.0
    24. imagePullPolicy: IfNotPresent