cluster-nacos

  • MySQL: 参考 external-mysql 文章

  • Pod 多节点反亲和性调度,单节点失效

  • Node 调度, 只运行在指定的节点上

[root@master test]# cat cluster-nacos-statefulset.yaml 
# nacos 配置
apiVersion: v1
kind: ConfigMap
metadata:
  name: nacos-sta-cm
data:
  mysql.host: "external-mysql"
  mysql.db.name: "nacos_config"
  mysql.port: "3306"
  mysql.user: "root"
  mysql.password: "123456"
---
apiVersion: v1
kind: Service
metadata:
  name: nacos-sta-svc
  labels:
    app: nacos-sta-svc
spec:
  type: NodePort
  ports:
    - name: server
      port: 8848
      protocol: TCP
      targetPort: 8848
      nodePort: 30848
    - name: client-rpc
      port: 9848
      protocol: TCP
      targetPort: 9848
      nodePort: 30948
    - name: raft-rpc
      port: 9849
      protocol: TCP
      targetPort: 9849
      nodePort: 30949
  selector:
    app: nacos
---
# Mysql SQL 地址: https://github.com/alibaba/nacos/tree/2.2.3/distribution/conf
apiVersion: apps/v1
kind: StatefulSet
#kind: Deployment
metadata:
  name: nacos
spec:
  serviceName: nacos-sta-svc
  selector:
    matchLabels:
      app: nacos
  replicas: 3
  template:
    metadata:
      labels:
        app: nacos
    spec:
      # 节点打上中间件标签并污染:kubectl taint nodes <node-name> middleware=true:NoSchedule
      #tolerations:
      #  - key: "middleware"
      #    operator: "Equal"
      #    value: "true"
      #    effect: "NoSchedule"

      # 当多节点生效:不允许同一个pod调度到同一个节点
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - middleware
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: nacos
          imagePullPolicy: IfNotPresent
          image: nacos/nacos-server:v2.2.3
          resources:
            requests:
              memory: "200Mi"
              cpu: "0.1"
            limits:
              memory: "2Gi"
              cpu: "1"
          livenessProbe:
            httpGet:
              path: /nacos/v1/console/health/liveness
              port: 8848
              scheme: HTTP
            failureThreshold: 10
            initialDelaySeconds: 10
            periodSeconds: 5
            timeoutSeconds: 1
          readinessProbe:
            httpGet:
              path: /nacos/v1/console/health/liveness
              port: 8848
              scheme: HTTP
            failureThreshold: 10
            initialDelaySeconds: 10
            periodSeconds: 5
            timeoutSeconds: 1
          ports:
            - containerPort: 8848
              name: client
          env:
            - name: SPRING_DATASOURCE_PLATFORM
              value: mysql
            - name: MYSQL_SERVICE_HOST
              valueFrom:
                configMapKeyRef:
                  name: nacos-sta-cm
                  key: mysql.host
            - name: MYSQL_SERVICE_DB_NAME
              valueFrom:
                configMapKeyRef:
                  name: nacos-sta-cm
                  key: mysql.db.name
            - name: MYSQL_SERVICE_PORT
              valueFrom:
                configMapKeyRef:
                  name: nacos-sta-cm
                  key: mysql.port
            - name: MYSQL_SERVICE_USER
              valueFrom:
                configMapKeyRef:
                  name: nacos-sta-cm
                  key: mysql.user
            - name: MYSQL_SERVICE_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: nacos-sta-cm
                  key: mysql.password
            - name: MODE
              value: "cluster"
            - name: NACOS_REPLICAS
              value: "3"
            - name: NACOS_AUTH_ENABLE
              value: "true"
            - name: NACOS_AUTH_IDENTITY_KEY
              value: "nacos"
            - name: NACOS_AUTH_IDENTITY_VALUE
              value: "nacos"
            - name: NACOS_AUTH_TOKEN
              value: "SecretKey012345678901234567890123456789012345678901234567890123456789"
            - name: NACOS_SERVER_PORT
              value: "8848"
            - name: PREFER_HOST_MODE
              value: "hostname"
            - name: NACOS_SERVERS
              value: >-
                nacos-0.nacos-sta-svc.default.svc.cluster.local:8848
                nacos-1.nacos-sta-svc.default.svc.cluster.local:8848
                nacos-2.nacos-sta-svc.default.svc.cluster.local:8848

Last updated