Sign In Try Free

Access the TiDB Cluster

This document describes how to access the TiDB cluster.

You can configure Service with different types according to the scenarios, such asClusterIP,NodePort,LoadBalancer, etc., and use different access methods for different types.

You can obtain TiDB Service information by running the following command:


              
kubectl get svc${serviceName}-n${namespace}

For example:


              
# kubectl get svc basic-tidb -n default NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE basic-tidb NodePort 10.233.6.240 4000:32498/TCP,10080:30171/TCP 61d

The above example describes the information of thebasic-tidbservice in thedefaultnamespace. The type isNodePort, ClusterIP is10.233.6.240, ServicePort is4000and10080, and the corresponding NodePort is32498and30171.

ClusterIP

ClusterIPexposes services through the internal IP of the cluster. When selecting this type of service, you can only access it within the cluster by the following methods:

  • ClusterIP + ServicePort
  • Service domain name (${serviceName}.${namespace}) + ServicePort

NodePort

If there is no LoadBalancer, you can choose to expose the service through NodePort. NodePort exposes services through the node's IP and static port. You can access a NodePort service from outside of the cluster by requestingNodeIP + NodePort.

To view the Node Port assigned by Service, run the following commands to obtain the Service object of TiDB:


              
kubectl -n${namespace}get svc${cluster_name}-tidb -ojsonpath="{.spec.ports[?(@.name=='mysql-client')].nodePort}{'\n'}"

检查您可以访问DB services by using the IP of what nodes, see the following two cases:

  • WhenexternalTrafficPolicyis configured asCluster, you can use the IP of any node to access TiDB services.

  • WhenexternalTrafficPolicyis configured asLocal, use the following commands to get the nodes where the TiDB instance of a specified cluster is located:

    
                    
    kubectl -n${namespace}get pods -l"app.kubernetes.io/component=tidb,app.kubernetes.io/instance=${cluster_name}"-ojsonpath="{range .items[*]}{.spec.nodeName}{'\n'}{end}"

LoadBalancer

If the TiDB cluster runs in an environment with LoadBalancer, such as on Google Cloud or AWS, it is recommended to use the LoadBalancer feature of these cloud platforms by settingtidb.service.type=LoadBalancer.

To access TiDB Service through LoadBalancer, refer toEKS,GKEandACK.

SeeKubernetes Service Documentationto know more about the features of Service and what LoadBalancer in the cloud platform supports.

Download PDF Request docs changes Ask questions on Discord
Playground
New
One-stop & interactive experience of TiDB's capabilities WITHOUT registration.
Was this page helpful?
Products
TiDB
TiDB Dedicated
TiDB Serverless
Pricing
Get Demo
Get Started
©2023PingCAP. All Rights Reserved.