k8s安装seata单机版
1.初始seata数据库
wget https://raw.githubusercontent.com/apache/incubator-seata/1.3.0/script/server/db/mysql.sql
mysql -uroot -p
CREATE DATABASE IF NOT EXISTS seata DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
use seata;
source /root/mysql.sql;
CREATE USER 'seata'@'%' IDENTIFIED BY 'MXl#GX8hw0wEv!ID';
GRANT ALL PRIVILEGES ON seata.* TO 'seata'@'%';
FLUSH PRIVILEGES;
exit;
2.创建seata配置文件
registry.conf
apiVersion: v1
kind: ConfigMap
metadata:
name: t1-zdbl-seata-server-registry-config
namespace: t1-zdbl
data:
registry.conf: |
registry {
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "t1-zdbl-nacos.t1-zdbl.svc.cluster.local:8848"
group = "SEATA_GROUP"
namespace = "seata"
cluster = "default"
username = "nacos"
password = "m5LqrxYsD7N1F6Cb"
}
}
config {
type = "file"
file {
name = "file:/seata-server/resources/file.conf"
}
}
file.conf
apiVersion: v1
kind: ConfigMap
metadata:
name: t1-zdbl-seata-server-file-config
namespace: t1-zdbl
data:
file.conf: |
store {
mode = "db"
db {
datasource = "druid"
dbType = "mysql"
driverClassName = "com.mysql.cj.jdbc.Driver"
url = "jdbc:mysql://t1-zdbl-mysql.t1-zdbl.svc.cluster.local:3306/t1_zdbl_seata?useUnicode=true&characterEncoding=UTF-8"
user = "seata"
password = "xxxxx" #连接nacos的密码不能包含特殊字符,否则会报错,403无法注册
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
3.创建部署文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: t1-zdbl-seata-server
namespace: t1-zdbl
labels:
k8s-app: t1-zdbl-seata-server
spec:
replicas: 1
selector:
matchLabels:
k8s-app: t1-zdbl-seata-server
template:
metadata:
labels:
k8s-app: t1-zdbl-seata-server
spec:
containers:
- name: seata-server
image: seataio/seata-server:1.3.0
#command: ["/bin/sh","-c","sleep 3600000"]
env:
- name: SEATA_PORT
value: "8091"
ports:
- name: http
containerPort: 8091
protocol: TCP
volumeMounts:
- mountPath: /seata-server/resources/file.conf
name: seata-file-conf
subPath: file.conf
- mountPath: /seata-server/resources/registry.conf
name: seata-register-conf
subPath: registry.conf
volumes:
- name: seata-file-conf
configMap:
defaultMode: 420
name: t1-zdbl-seata-server-file-config
- name: seata-register-conf
configMap:
defaultMode: 420
name: t1-zdbl-seata-server-registry-config
4.创建svc文件
apiVersion: v1
kind: Service
metadata:
name: t1-zdbl-seata-server
namespace: t1-zdbl
labels:
k8s-app: t1-zdbl-seata-server
spec:
ports:
- port: 8091
targetPort: 8091
protocol: TCP
name: http
selector:
k8s-app: t1-zdbl-seata-server
初始化数据库后,应用以上文件即可
"一劳永逸" 的话,有是有的,而 "一劳永逸" 的事却极少