K8S 部署 seata
文章目录
- 创建 Deployment 文件
- 创建 ConfigMap 文件
- 创建 Service 文件
- 运行
- 访问
- 高可用部署
- 踩坑
官方文档
k8s中volumeMounts.subPath的巧妙用法
创建 Deployment 文件
deploymemt.yaml
- namespace:指定命名空间
- image:使用 1.5.2 版本的镜像
- ports:暴露 8091 和 7091 端口
- volumeMounts:容器中的存储
- mountPath: 存储路径
- subPath:指定出具体文件
- volumes:pod 存储
- configMap.name:对应 configMap 文件的 metadata. name
apiVersion: apps/v1
kind: Deployment
metadata:name: seata-servernamespace: commonlabels:k8s-app: seata-server
spec:replicas: 1selector:matchLabels:k8s-app: seata-servertemplate:metadata:labels:k8s-app: seata-serverspec:containers:- name: seata-serverimage: docker.io/seataio/seata-server:1.5.2imagePullPolicy: IfNotPresentports:- name: http-7091containerPort: 7091protocol: TCP- name: http-8091containerPort: 8091protocol: TCPvolumeMounts:- name: seata-configmountPath: /seata-server/resources/application.ymlsubPath: application.ymlvolumes:- name: seata-configconfigMap:name: seata-server-config
创建 ConfigMap 文件
configmap.yaml
映射 application.yml 文件,例子使用 seata 原始配置文件
apiVersion: v1
kind: ConfigMap
metadata:name: seata-server-confignamespace: common
data:application.yml: |server:port: 7091spring:application:name: seata-serverlogging:config: classpath:logback-spring.xmlfile:path: ${user.home}/logs/seataextend:logstash-appender:destination: 127.0.0.1:4560kafka-appender:bootstrap-servers: 127.0.0.1:9092topic: logback_to_logstashconsole:user:username: seatapassword: seataseata:config:# support: nacos, consul, apollo, zk, etcd3type: fileregistry:# support: nacos, eureka, redis, zk, consul, etcd3, sofatype: filestore:# support: file 、 db 、 redismode: file# server:# service-port: 8091 #If not configured, the default is '${server.port} + 1000'security:secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017tokenValidityInMilliseconds: 1800000ignore:urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
创建 Service 文件
service.yaml
对外暴露 NodePort 端口
apiVersion: v1
kind: Service
metadata:name: seata-servernamespace: commonlabels:k8s-app: seata-server
spec:type: NodePortports:- port: 8091nodePort: 30893protocol: TCPname: seata-8091- port: 7091nodePort: 30793protocol: TCPname: seata-7091selector:k8s-app: seata-server
运行
kubectl apply -f deployment.yaml
kubectl apply -f configmap.yaml
kubectl apply -f service.yaml
访问
访问 ip:30793 即可访问 seata
默认账号:seata
默认密码:seata
高可用部署
修改 configmap 映射的 application.yml 文件
- seata.config:配置 seata 配置文件路径
- seata.registry:配置 seata 注册地址
seata:config:type: nacosnacos:server-addr: nacosIp:portnamespace: seatagroup: devusername: nacospassword: nacosdata-id: seata-dev.ymlregistry:type: nacosnacos:application: seata-serverserver-addr: nacosIp:portgroup: devnamespace: seatacluster: defaultusername: nacospassword: nacos
deployment 添加多个 pod
成功注册上 nacos
踩坑
-
问题:按照官方文档 Seata 高可用部署,镜像使用 1.5.0 及以上的版本时,seata 无法正常注册到 nacos
解决办法:镜像使用 1.4.2 版本 -
问题:使用 1.4.2 版本版本后,高可用还是有问题,nodeport 暴露后无法访问
解决办法:使用本文部署