在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.