文章目录
- 创建 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-server
namespace: common
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:1.5.2
imagePullPolicy: IfNotPresent
ports:
- name: http-7091
containerPort: 7091
protocol: TCP
- name: http-8091
containerPort: 8091
protocol: TCP
volumeMounts:
- name: seata-config
mountPath: /seata-server/resources/application.yml
subPath: application.yml
volumes:
- name: seata-config
configMap:
name: seata-server-config
创建 ConfigMap 文件
configmap.yaml
映射 application.yml 文件,例子使用 seata 原始配置文件
apiVersion: v1
kind: ConfigMap
metadata:
name: seata-server-config
namespace: common
data:
application.yml: |
server:
port: 7091
spring:
application:
name: seata-server
logging:
config: classpath:logback-spring.xml
file:
path: ${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
seata:
config:
# support: nacos, consul, apollo, zk, etcd3
type: file
registry:
# support: nacos, eureka, redis, zk, consul, etcd3, sofa
type: file
store:
# support: file 、 db 、 redis
mode: file
# 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,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
创建 Service 文件
service.yaml
对外暴露 NodePort 端口
apiVersion: v1
kind: Service
metadata:
name: seata-server
namespace: common
labels:
k8s-app: seata-server
spec:
type: NodePort
ports:
- port: 8091
nodePort: 30893
protocol: TCP
name: seata-8091
- port: 7091
nodePort: 30793
protocol: TCP
name: seata-7091
selector:
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: nacos
nacos:
server-addr: nacosIp:port
namespace: seata
group: dev
username: nacos
password: nacos
data-id: seata-dev.yml
registry:
type: nacos
nacos:
application: seata-server
server-addr: nacosIp:port
group: dev
namespace: seata
cluster: default
username: nacos
password: nacos
deployment 添加多个 pod
成功注册上 nacos
踩坑
-
问题:按照官方文档 Seata 高可用部署,镜像使用 1.5.0 及以上的版本时,seata 无法正常注册到 nacos
解决办法:镜像使用 1.4.2 版本 -
问题:使用 1.4.2 版本版本后,高可用还是有问题,nodeport 暴露后无法访问
解决办法:使用本文部署