正文

在K8S集成seata,官方配置

代码

在这里插入图片描述

apiVersion: v1
kind: Service
metadata:
  name: seata-server
  namespace: wmz-dev
  labels:
    k8s-app: seata-server
spec:
  type: NodePort
  ports:
    - port: 8091
      nodePort: 30091
      protocol: TCP
      name: http
  selector:
    k8s-app: seata-server

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: seata-server
  namespace: wmz-dev
  labels:
    k8s-app: seata-server
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: seata-server
  template:
    metadata:
      labels:
        k8s-app: seata-server
    spec:
      containers:
        - name: seata-server
          image: docker.io/seataio/seata-server:latest
          imagePullPolicy: IfNotPresent
          env:
            - name: SEATA_CONFIG_NAME
              value: file:/root/seata-config/registry.conf
          ports:
            - name: http
              containerPort: 8091
              protocol: TCP
          volumeMounts:
            - name: seata-config
              mountPath: /root/seata-config
      volumes:
        - name: seata-config
          configMap:
            name: seata-server-config
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: seata-server-config
data:
  registry.conf: |
    registry {
        type = "nacos"
        nacos {
          application = "seata-server"
          serverAddr = "192.168.199.2"
          cluster= "default"
          group = "WEIMEIZI_GROUP"
          username = "nacos" 
          password = "nacos" 
        }
    }
    config {
      type = "nacos"
      nacos {
        serverAddr = "192.168.199.2"
        group = "SEATA_GROUP"
        group = "WEIMEIZI_GROUP" 
        username = "nacos" 
        password = "nacos" 

      }
    }

配置文件主要看中间和最底下的代码

中间:主要看

env:
            - name: SEATA_CONFIG_NAME
              value: file:/root/seata-config/registry.conf

这代表指定配置文件,下面则是指定ConfigMap

ConfigMap则是seata的config/application.properties文件里的内容

创建后,在阿里的配置项会有这个配置
在这里插入图片描述
如果已经有配置项,创建K8S时可以去掉最底层代码

重要

在K8S创建seata,可能在nacos看不到seata的服务,但实际上,seata已经成功运行,并且系统也把事务托管给了seata,我就是这个样子的,nacos找不到,还以为seata没注册成功
在这里插入图片描述

nacos配置文件

在这里插入图片描述
改了以后,虽然在nacos的服务列表没有seata,但是看了seata的启动日志,发现它已经把系统的事务进行托管,经测试,分布式事务也能正常回滚

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐