• 已删除用户
Administrator
发布于 2023-07-25 / 8 阅读
0

K8S部署Nacos(集群版)

以下YAML文件从本地搭建的KubeSphere工作负载中导出,可能因关联保密字典Secret、配置字典ConfigMap、服务Service等无法直接运行,仅供参考。

kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: nacos
  namespace: supports
  annotations:
    kubesphere.io/creator: admin
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nacos
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nacos
      annotations:
        kubesphere.io/creator: admin
        kubesphere.io/imagepullsecrets: '{}'
        kubesphere.io/restartedAt: '2023-07-25T03:08:10.088Z'
        pod.alpha.kubernetes.io/initialized: 'true'
    spec:
      volumes:
        - name: host-time
          hostPath:
            path: /etc/localtime
            type: ''
      containers:
        - name: nacos
          image: 'nacos/nacos-server:latest'
          ports:
            - name: client
              containerPort: 8848
              protocol: TCP
            - name: client-rpc
              containerPort: 9848
              protocol: TCP
            - name: raft-rpc
              containerPort: 9849
              protocol: TCP
            - name: old-raft-rpc
              containerPort: 7848
              protocol: TCP
          env:
            - name: NACOS_REPLICAS
              value: '3'
            - name: MYSQL_SERVICE_HOST
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.host
            - name: MYSQL_SERVICE_DB_NAME
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.db.name
            - name: MYSQL_SERVICE_PORT
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.port
            - name: MYSQL_SERVICE_USER
              valueFrom:
                secretKeyRef:
                  name: mysql-nacos-secret
                  key: username
            - name: MYSQL_SERVICE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-nacos-secret
                  key: password
            - name: SPRING_DATASOURCE_PLATFORM
              value: mysql
            - name: NACOS_SERVER_PORT
              value: '8848'
            - name: NACOS_APPLICATION_PORT
              value: '8848'
            - name: PREFER_HOST_MODE
              value: hostname
            - name: NACOS_SERVERS
              value: >-
                nacos-0.nacos-headless.supports.svc.cluster.local:8848
                nacos-1.nacos-headless.supports.svc.cluster.local:8848
                nacos-2.nacos-headless.supports.svc.cluster.local:8848
          resources: {}
          volumeMounts:
            - name: host-time
              readOnly: true
              mountPath: /etc/localtime
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: app
                    operator: In
                    values:
                      - nacos-headless
              topologyKey: kubernetes.io/hostname
      schedulerName: default-scheduler
  serviceName: nacos-headless
  podManagementPolicy: OrderedReady
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      partition: 0
  revisionHistoryLimit: 10

注意:需要提前初始化数据库 nacos-mysql-schema.sql