写在最前

https://seata.apache.org/zh-cn/docs/v2.0/overview/what-is-seata

1. docker 部署

2. kubernetes 部署

2.1 configmap

kind: ConfigMap
apiVersion: v1
metadata:
  name: seata-ha-server-config
  namespace: crpem
  annotations:
    kubesphere.io/creator: admin
data:
  application.yml: |-
    #  Copyright 1999-2019 Seata.io Group.
    #
    #  Licensed under the Apache License, Version 2.0 (the "License");
    #  you may not use this file except in compliance with the License.
    #  You may obtain a copy of the License at
    #
    #  http://www.apache.org/licenses/LICENSE-2.0
    #
    #  Unless required by applicable law or agreed to in writing, software
    #  distributed under the License is distributed on an "AS IS" BASIS,
    #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    #  See the License for the specific language governing permissions and
    #  limitations under the License.

    server:
      port: 7091

    spring:
      application:
        name: seata-server

    logging:
      config: classpath:logback-spring.xml
      file:
        path: ${log.home:${user.home}/logs/seata}
      extend:
        logstash-appender:
          destination: 127.0.0.1:4560
        kafka-appender:
          bootstrap-servers: 127.0.0.1:9092
          topic: logback_to_logstash

    console:
      user:
        username: seata
        password: ??????
    seata:
      config:
        # support: nacos, consul, apollo, zk, etcd3
        type: nacos
      registry:
        # support: nacos, eureka, redis, zk, consul, etcd3, sofa
        type: nacos
      store:
        # support: file 、 db 、 redis 、 raft
        mode: db
      #  server:
      #    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
      security:
        secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
        tokenValidityInMilliseconds: 1800000
        ignore:
          urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/metadata/v1/**
  registry.conf: |-
    registry {
      type = "nacos"

      nacos {
        application = "seata-server"
        serverAddr = "nacos-vip.bx:8848"
        namespace = "crpem"
        cluster = "default"
        username = "crpem"
        password = "??????"
      }
    }

    config {
      type = "nacos"
      
      nacos {
        serverAddr = "nacos-vip.bx:8848"
        namespace = "crpem"
        group = "DEFAULT_GROUP"
        username = "crpem"
        password = "??????"
        data-id: seataServer.properties
      }
    }

2.2 deployment

kind: Deployment
apiVersion: apps/v1
metadata:
  name: seata-ha-server
  namespace: crpem
  labels:
    app.kubernetes.io/name: seata-ha-server
  annotations:
    deployment.kubernetes.io/revision: '2'
    kubesphere.io/creator: admin
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: seata-ha-server
  template:
    metadata:
      creationTimestamp: null
      labels:
        app.kubernetes.io/name: seata-ha-server
      annotations:
        kubesphere.io/creator: admin
        kubesphere.io/imagepullsecrets: '{"seata-ha-server":"harbor-dev"}'
        kubesphere.io/restartedAt: '2025-09-18T02:56:30.785Z'
        logging.kubesphere.io/logsidecar-config: '{}'
    spec:
      volumes:
        - name: seata-config
          configMap:
            name: seata-ha-server-config
            defaultMode: 420
        - name: volume-89o4te
          configMap:
            name: seata-ha-server-config
            items:
              - key: application.yml
                path: application.yml
            defaultMode: 420
      containers:
        - name: seata-ha-server
          image: 'seataio/seata-server:2.0.0'
          ports:
            - name: tcp-7091
              containerPort: 7091
              protocol: TCP
            - name: tcp-8091
              containerPort: 8091
              protocol: TCP
          env:
            - name: SEATA_CONFIG_NAME
              value: 'file:/root/seata-config/registry'
          resources: {}
          volumeMounts:
            - name: seata-config
              mountPath: /root/seata-config
            - name: volume-89o4te
              readOnly: true
              mountPath: /seata-server/resources/application.yml
              subPath: application.yml
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      imagePullSecrets:
        - name: harbor-dev
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/name: seata-ha-server
                topologyKey: kubernetes.io/hostname
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600

2.3 service

kind: Service
apiVersion: v1
metadata:
  name: seata-ha-server
  namespace: crpem
  labels:
    app.kubernetes.io/name: seata-ha-server
  annotations:
    kubesphere.io/creator: admin
spec:
  ports:
    - name: http-8091
      protocol: TCP
      port: 8091
      targetPort: 8091
    - name: http-7091
      protocol: TCP
      port: 7091
      targetPort: 7091
  selector:
    app.kubernetes.io/name: seata-ha-server
  type: ClusterIP
  sessionAffinity: None
  ipFamilies:
    - IPv4
  ipFamilyPolicy: SingleStack
  internalTrafficPolicy: Cluster

2.4 seataServer.properties

该配置文件在上文registry.conf的nacos中创建,sql文件可以到github中下载

#事务会话信息存储方式
store.mode=db
#事务锁信息存储方式
store.lock.mode=db
#事务回话信息存储方式
store.session.mode=db

#存储方式为db, 设置使用的存储类型是 mysql
store.db.dbType=mysql
store.db.datasource=druid
store.db.driverClassName=com.mysql.cj.jdbc.Driver
# 下方你的数据库名称如果不是 seata 记得修正
store.db.url=jdbc:mysql://172.31.0.111:3306/seata?useUnicode=true&rewriteBatchedStatements=true&useSSL=false
store.db.user=??????
store.db.password=??????
store.db.minConn=5
store.db.maxConn=30
store.db.queryLimit=100
store.db.maxWait=5000
# 下面 4 项对应的数据库中几张数据表
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.lockTable=lock_table
store.db.distributedLockTable=distributed_lock

写在最后