K8S部署nacos与seata

最近开始搞k8s了,记录一下。

mysql

我mysql没有使用容器,该怎么部署怎么部署,不是这里的重点。

nacos

参考:https://nacos.io/zh-cn/docs/use-nacos-with-kubernetes.html

我使用的最简单的模式,没有用到PV。

导入好DB

mkdir install-apps/nacos -p
cd install-apps/nacos
git clone https://github.com/nacos-group/nacos-k8s.git
cd nacos-k8s

编辑 deploy/nacos/nacos-no-pvc-ingress.yaml,修改需要变化的参数即可。
单机模式:(总是不用mysql而用它内置的,研究了好久,终于搞定)

data:
  mysql.host: "DB地址"
  mysql.db.name: "nacos"
  mysql.port: "3306"
  mysql.user: "root"
  mysql.password: "123456"
  spring.ds: "mysql"
#kind:StatefulSet下
spec.replicas: 1
spec.spec.containers.imagePullPolicy: IfNotPresent
spec.spec.containers.resources.requests.memory: "1Gi"
spec.spec.containers.env
  - name: NACOS_REPLICAS
    value: "1"
  - name: SPRING_DATASOURCE_PLATFORM
    valueFrom:
      configMapKeyRef:
        name: nacos-cm
        key: spring.ds
  - name: MODE
    value: "standalone"
  - name: NACOS_SERVERS
    value: "nacos-0.nacos-headless.default.svc.cluster.local:8848"

#kind: Ingress下
spec.rules.host: nacos.XXXXX.com

3个副本的集群模式:(1个副本的集群模式注册时会报错!)

data:
  mysql.host: "DB地址"
  mysql.db.name: "nacos"
  mysql.port: "3306"
  mysql.user: "root"
  mysql.password: "123456"
#kind:StatefulSet下
spec.replicas: 3
spec.spec.containers.imagePullPolicy: IfNotPresent
spec.spec.containers.resources.requests.memory: "1Gi"
spec.spec.containers.env
            - name: NACOS_REPLICAS
              value: "3"
           - name: NACOS_SERVERS
              value: "nacos-0.nacos-headless.default.svc.cluster.local:8848,nacos-1.nacos-headless.default.svc.cluster.local:8848,nacos-2.nacos-headless.default.svc.cluster.local:8848"
#kind: Ingress下
spec.rules.host: nacos.XXXXX.com
kubectl apply -f deploy/nacos/nacos-no-pvc-ingress.yaml

如果是没解析的域名,记得改电脑、各master与各worker的host文件:

XXX.XXX.XXX.XXX nacos.XXXXX.com

查询ingress的暴露端口

kubectl get svc -n ingress-nginx

seata

参考:
http://seata.io/zh-cn/docs/ops/deploy-by-kubernetes.html
https://zhizhebuyan.com/2020/06/08/Seata%E5%9C%A8kubernetes%E4%B8%AD%E4%BD%BF%E7%94%A8%E8%87%AA%E5%AE%9A%E4%B9%89%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%88%9B%E5%BB%BA%E6%9C%8D%E5%8A%A1/

我用的mysql部署模式,svc用的nodePort。

cd seata-k8s/
vim deploy/seata-deploy.yaml

导入好DB

mkdir install-apps/seata -p
cd install-apps/seata

编辑 seata-server.yml,这是全的照抄即可

apiVersion: v1
kind: Service
metadata:
  name: seata-server
  namespace: default
  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: default
  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
          ports:
            - name: http
              containerPort: 8091
              protocol: TCP
          volumeMounts:
            - name: seata-config
              mountPath: /root/seata-config
            - name: seata-file
              mountPath: /root/seata-config-file
      volumes:
        - name: seata-config
          configMap:
            name: seata-server-config
        - name: seata-file
          configMap:
            name: seata-server-file
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: seata-server-config
data:
  # 下面两个nacos地址的default记得换成需要的namespace
  registry.conf: |
    registry {
        type = "nacos"
        nacos {
          application = "seata-server"
          serverAddr = "nacos-headless.default.svc.cluster.local"
        }
    }
    config {
      type = "nacos"
      nacos {
        serverAddr = "nacos-headless.default.svc.cluster.local"
        group = "SEATA_GROUP"
        username = "nacos"
        password = "123456"
      }
    }
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: seata-server-file
data:
  file.conf: |
    store {
        mode = "db"
        db {
            datasource = "druid"
            dbType = "mysql"
            driverClassName = "com.mysql.jdbc.Driver"
            url = "jdbc:mysql://DB地址:3306/seata?useUnicode=true"
            user = "root"
            password = "123456"
            minConn = 5
            maxConn = 30
            globalTable = "global_table"
            branchTable = "branch_table"
            lockTable = "lock_table"
            queryLimit = 100
            maxWait = 5000
        }
    }
kubectl apply -f seata-server.yml

小功告成~ 后面再搞别的服务~

附一个测试或调试用的pod的yaml

apiVersion: v1
kind: Pod
metadata:
  name: mytest
  namespace: 你使用的命名空间
spec:
  containers:
  - name: mytest
    image: busybox
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
0 0 votes
文章评分
订阅
提醒
guest
0 评论
最旧
最新 得票最多