Kubernetes 上部署Seata-Server

2021-02-05  本文已影响0人  InGramViking

官方文档

官方K8s部署文档
官方高可用部署文档
Git仓库

Seata高可用部署

1、注册中心、配置中心使用nacos
2、数据库使用RDS
3、Nacos地址为192.168.199.2
4、使用阿里云SLB暴露应用(和nacos用一个SLB实例即可)

目录结构

$ ll -R
total 32
-rw-r--r-- 1 localhost staff 303 2 2 12:12 config.txt
drwxr-xr-x 3 localhost staff 96 2 2 12:20 nacos
-rw-r--r-- 1 localhost staff 808 2 2 12:19 seata-client.sql
-rw-r--r-- 1 localhost staff 1899 2 2 12:19 seata-server.sql
-rw-r--r-- 1 localhost staff 1864 2 4 10:33 seata-server.yaml

./nacos:
total 8
-rwxr-xr-x 1 localhost staff 2936 2 2 12:20 nacos-config.sh

部署前准备

同时,也需要创建 undo_log 表, 可以参考 script/client/at/db/

将以下配置保存为config.txt

service.vgroupMapping.my_test_tx_group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://rm-2zeabcdefghijklmn.mysql.rds.aliyuncs.com/seata?useUnicode=true
store.db.user=nacos
store.db.password=password

shell:

sh ./nacos/nacos-config.sh -h 192.168.199.2 -p 8848 -g SEATA_GROUP -u username -w password

参数说明:

-h: Nacos主机地址,默认是localhost

-p: Nacos主机端口,默认是8848

-g: 配置分组, the default value is 'SEATA_GROUP'.

-t: 租户信息, 与Nacos的 "命名空间ID" 字段相对应, the default value is ''.

-u: Nacos用户名, the default value is ''.

-w: Nacos密码, the default value is ''.

部署 seata-server 到 Kubernetes

$ kubectl apply -f seata-server.yaml
apiVersion: v1
kind: Service
metadata:
  name: seata-ha-server
  namespace: pluginprod
  labels:
    app.kubernetes.io/name: seata-ha-server
  #annotations:
  #  service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id: lb-2zeabcdefghijklmn
  #  service.beta.kubernetes.io/alicloud-loadbalancer-force-override-listeners: 'true'
spec:
  #type: LoadBalancer
  type: ClusterIP
  ports:
    - port: 8091
      protocol: TCP
      targetPort: 8091
      name: http
  selector:
    app.kubernetes.io/name: seata-ha-server

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: seata-ha-server-config
  namespace: pluginprod
data:
  registry.conf: |
    registry {
        type = "nacos"
        nacos {
          application = "seata-server"
          serverAddr = "192.168.199.2"
        }
    }
    config {
      type = "nacos"
      nacos {
        serverAddr = "192.168.199.2"
        group = "SEATA_GROUP"
      }
    }
---

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: seata-ha-server
  namespace: pluginprod
  labels:
    app.kubernetes.io/name: seata-ha-server
spec:
  serviceName: seata-ha-server
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: seata-ha-server
  template:
    metadata:
      labels:
        app.kubernetes.io/name: seata-ha-server
    spec:
      containers:
        - name: seata-ha-server
          image: docker.io/seataio/seata-server:latest
          imagePullPolicy: IfNotPresent
          env:
            - name: SEATA_CONFIG_NAME
              value: file:/root/seata-config/registry
          ports:
            - name: http
              containerPort: 8091
              protocol: TCP
          volumeMounts:
            - name: seata-config
              mountPath: /root/seata-config
      volumes:
        - name: seata-config
          configMap:
            name: seata-ha-server-config
上一篇下一篇

猜你喜欢

热点阅读