apiVersion: apps/v1 kind: StatefulSet metadata: labels: app: nacos component: nacos middleware: nacos name: nacos namespace: nacos spec: podManagementPolicy: Parallel replicas: 3 revisionHistoryLimit: 10 selector: matchLabels: app: nacos component: nacos middleware: nacos serviceName: nacos-headless template: metadata: labels: app: nacos component: nacos middleware: nacos spec: containers: - command: - sh - -c - "array=(nacos-0.nacos-headless.nacos.svc.cluster.local nacos-1.nacos-headless.nacos.svc.cluster.local nacos-2.nacos-headless.nacos.svc.cluster.local )\nsucc = 0\n\nfor element in ${array[@]} \ndo\n while true\n do\n ping $element -c 1 > /dev/stdout\n \ if [[ $? -eq 0 ]]; then\n echo $element "all domain ready"\n \ break\n else\n echo $element "wait for other domain ready"\n \ fi\n sleep 1\n done\ndone\nsleep 1\n\necho "init success"&&bin/docker-startup.sh" env: - name: PREFER_HOST_MODE value: hostname - name: SPRING_DATASOURCE_PLATFORM value: mysql - name: MYSQL_SERVICE_HOST value: 192.168.123.50 - name: MYSQL_SERVICE_PORT value: "58665" - name: MYSQL_SERVICE_DB_NAME value: nacos - name: MYSQL_SERVICE_USER value: nacos - name: MYSQL_SERVICE_PASSWORD value: nacos - name: NACOS_REPLICAS value: "3" - name: NACOS_SERVERS value: nacos-0.nacos-headless.nacos.svc.cluster.local:8848 nacos-1.nacos-headless.nacos.svc.cluster.local:8848 nacos-2.nacos-headless.nacos.svc.cluster.local:8848 - name: NACOS_AUTH_IDENTITY_KEY value: "5FWxUrJ9WUepFmnW" - name: NACOS_AUTH_IDENTITY_VALUE value: "5FWxUrJ9WUepFmnW" - name: NACOS_AUTH_TOKEN value: "SecretKeyNUZXeFVySjlXVWVwRm1uVwo=" #- name: NACOS_AUTH_ENABLE # value: "true" image: nacos/nacos-server:v2.2.1 imagePullPolicy: IfNotPresent name: nacos ports: - containerPort: 8848 name: client protocol: TCP - containerPort: 7848 name: rpc protocol: TCP - containerPort: 9848 name: new-rpc protocol: TCP resources: limits: cpu: "2" memory: 2Gi requests: cpu: 100m memory: 512Mi terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 updateStrategy: rollingUpdate: partition: 0 type: RollingUpdate
apiVersion: v1 kind: Service metadata: name: nacos-headless namespace: nacos spec: clusterIP: None clusterIPs: - None internalTrafficPolicy: Cluster ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - name: client port: 8848 protocol: TCP targetPort: 8848 - name: rpc port: 7848 protocol: TCP targetPort: 7848 - name: new-rpc port: 9848 protocol: TCP targetPort: 9848 publishNotReadyAddresses: true selector: app: nacos component: nacos middleware: nacos sessionAffinity: None type: ClusterIP
apiVersion: v1 kind: Service metadata: annotations: labels: app: nacos component: nacos middleware: nacos name: nacos namespace: nacos spec: internalTrafficPolicy: Cluster ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - name: client port: 8848 protocol: TCP targetPort: 8848 publishNotReadyAddresses: true selector: app: nacos component: nacos middleware: nacos sessionAffinity: None type: NodePort
此回答整理自钉群“Nacos社区群3”