在Ubuntu上使用Kubernates (microk8s)跑TiDB

先建立一个namespace,就叫tidb

kubectl create namespace tidb

建立一个tidb的yaml文件,叫tidb.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tidb-deployment
  namespace: tidb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tidb
  template:
    metadata:
      labels:
        app: tidb
    spec:
      containers:
      - name: tidb
        image: pingcap/tidb:latest
        ports:
        - containerPort: 4000

---
apiVersion: v1
kind: Service
metadata:
  name: tidb-service
  namespace: tidb
spec:
  selector:
    app: tidb
  ports:
  - protocol: TCP
    port: 4000
    targetPort: 4000

用kubernates启动tidb

microk8s.kubectl apply -f tidb3.yaml

查看状态可以用以下命令

microk8s.kubectl get deployments -n tidb
microk8s.kubectl get pods -n tidb
microk8s.kubectl logs -n tidb <pod-name from above>
microk8s.kubectl get services -n tidb

安装mysql客户端,如果之前没有安装的话

sudo apt install mysql-client-core-8.0

连接tidb

mysql -h CLUSTER-IP -P PORT -u root -p

Leave a Comment

Your email address will not be published.