k8s 部署seata使用nacos作为配置中心

kind: Deployment
apiVersion: apps/v1
metadata:
  name: seata-v1
  namespace: health-examination-api
  labels:
    app: seata
    version: v1
  annotations:
    deployment.kubernetes.io/revision: '8'
    kubesphere.io/creator: project-admin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: seata
      version: v1
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: seata
        version: v1
      annotations:
        kubesphere.io/restartedAt: '2021-06-08T10:00:01.089Z'
        logging.kubesphere.io/logsidecar-config: '{}'
    spec:
      volumes:
        - name: volume-syfmi2
          configMap:
            name: seata-server-config
            defaultMode: 420
      containers:
        - name: seata
          image: 'seataio/seata-server:1.3.0'
          ports:
            - name: http-8091
              containerPort: 8091
              protocol: TCP
          env:
            - name: SEATA_CONFIG_NAME
              value: 'file:/root/seata-config/registry'
          resources:
            limits:
              cpu: 500m
              memory: 500Mi
          volumeMounts:
            - name: volume-syfmi2
              readOnly: true
              mountPath: /root/seata-config
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      serviceAccountName: default
      serviceAccount: default
      securityContext: {}
      affinity: {}
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
---


kind: Service
apiVersion: v1
metadata:
  name: seata
  namespace: health-examination-api
  labels:
    app: seata
    version: v1
  annotations:
    kubesphere.io/creator: project-admin
    kubesphere.io/serviceType: statelessservice
spec:
  ports:
    - name: http-8091
      protocol: TCP
      port: 8091
      targetPort: 8091
  selector:
    app: seata
  clusterIP: 10.233.52.13
  type: ClusterIP
  sessionAffinity: None

---

kind: ConfigMap
apiVersion: v1
metadata:
  name: seata-server-config
  namespace: health-examination-api
  annotations:
    kubesphere.io/creator: project-admin
data:
  registry.conf: |
    registry {
        type = "nacos"
        nacos {
          group="SEATA_GROUP"
          namespace ="public"
          application = "seata-server"
          serverAddr = "nacos.health-examination-api.172.30.42.196.nip.io:30328"
        }
    }
    config {
      type = "nacos"
      nacos {
        serverAddr = "nacos.health-examination-api.172.30.42.196.nip.io:30328"
        group="SEATA_GROUP"
        namespace="public"
      }
    }

 

### 在 Kubernetes 上部署 Seata 1.7 的方案 #### 准备工作 在 Kubernetes 中成功运行 Seata 高可用集群之前,需完成一些前置条件。首先需要创建 Seata 所依赖的服务数据库及其相关表结构[^3]。如果已有阿里云 RDS,则可以直接在其上建立名为 `seata` 的数据库,并导入官方提供的 SQL 脚本文件来初始化必要的表结构,特别是 `undo_log` 表[^4]。 #### 创建配置文件 为了使 Seata Server 正常启动并注册至 Nacos 或其他注册中心,在容器化环境中应特别注意其配置文件路径映射问题[^2]。可以通过挂载本地目录到 Pod 内部的方式实现自定义配置加载: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: seata-server-deployment spec: replicas: 3 selector: matchLabels: app: seata-server template: metadata: labels: app: seata-server spec: containers: - name: seata-server image: seataio/seata-server:v1.7 ports: - containerPort: 8091 volumeMounts: - mountPath: /seata-server/resources name: config-volume volumes: - name: config-volume hostPath: path: /User/seata/config ``` 上述 YAML 文件展示了如何通过 Kubernetes Deployment 对象部署三个副本的 Seata Server 实例,并将主机上的 `/User/seata/config` 映射到容器内的资源目录下。 #### 应用与验证 执行命令以应用配置并将服务暴露给内部网络访问: ```bash kubectl apply -f seata-1.7.yaml kubectl get pod,svc ``` 这一步骤用于确认 Pods 是否正常启动以及 Service 是否被正确创建[^1]。 --- ### 注意事项 确保所有的节点都能够连接到所选的注册中心(如 Nacos),并且防火墙规则允许端口通信。此外,调整好事务超时时间等参数也是保障分布式事务顺利进行的重要环节之一。 ---
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值