GitHub - nacos-group/nacos-k8s: This project contains a Nacos Docker image meant to facilitate the deployment of Nacos on Kubernetes using StatefulSets.
需要修改两个文件
---
apiVersion: v1
kind: Service
metadata:name: nacos-headlessnamespace: project-gulimalllabels:app: nacos-headless
spec:type: ClusterIPclusterIP: Noneports:- port: 8848name: servertargetPort: 8848- port: 9848name: client-rpctargetPort: 9848- port: 9849name: raft-rpctargetPort: 9849## 兼容1.4.x版本的选举端口- port: 7848name: old-raft-rpctargetPort: 7848selector:app: nacos
---
apiVersion: v1
kind: ConfigMap
metadata:name: nacos-cmnamespace: project-gulimall
data:mysql.host: "mysql"mysql.db.name: "nacos_devtest"mysql.port: "3306"mysql.user: "nacos"mysql.password: "nacos"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:name: nacosnamespace: project-gulimall
spec:serviceName: nacos-headlessreplicas: 3template:metadata:labels:app: nacosannotations:pod.alpha.kubernetes.io/initialized: "true"spec:containers:- name: nacosimagePullPolicy: Alwaysimage: nacos/nacos-server:latestresources:requests:memory: "2Gi"cpu: "500m"ports:- containerPort: 8848name: client- containerPort: 9848name: client-rpc- containerPort: 9849name: raft-rpc- containerPort: 7848name: old-raft-rpcenv:- name: NACOS_REPLICASvalue: "3"- name: MYSQL_SERVICE_HOSTvalueFrom:configMapKeyRef:name: nacos-cmkey: mysql.host- name: MYSQL_SERVICE_DB_NAMEvalueFrom:configMapKeyRef:name: nacos-cmkey: mysql.db.name- name: MYSQL_SERVICE_PORTvalueFrom:configMapKeyRef:name: nacos-cmkey: mysql.port- name: MYSQL_SERVICE_USERvalueFrom:configMapKeyRef:name: nacos-cmkey: mysql.user- name: MYSQL_SERVICE_PASSWORDvalueFrom:configMapKeyRef:name: nacos-cmkey: mysql.password- name: SPRING_DATASOURCE_PLATFORMvalue: "mysql"- name: NACOS_SERVER_PORTvalue: "8848"- name: NACOS_APPLICATION_PORTvalue: "8848"- name: PREFER_HOST_MODEvalue: "hostname"- name: NACOS_SERVERSvalue: "nacos-0.nacos-headless.project-gulimall.svc.cluster.local:8848 nacos-1.nacos-headless.project-gulimall.svc.cluster.local:8848 nacos-2.nacos-headless.project-gulimall.svc.cluster.local:8848"selector:matchLabels:app: nacos
apiVersion: v1
kind: ReplicationController
metadata:name: mysqlnamespace: project-gulimalllabels:name: mysql
spec:replicas: 1selector:name: mysqltemplate:metadata:labels:name: mysqlspec:containers:- name: mysqlimage: nacos/nacos-mysql:5.7ports:- containerPort: 3306volumeMounts:- name: mysql-datamountPath: /var/lib/mysqlenv:- name: MYSQL_ROOT_PASSWORDvalue: "root"- name: MYSQL_DATABASEvalue: "nacos_devtest"- name: MYSQL_USERvalue: "nacos"- name: MYSQL_PASSWORDvalue: "nacos"volumes:- name: mysql-datahostPath:path: /var/lib/mysql
---
apiVersion: v1
kind: Service
metadata:name: mysqlnamespace: project-gulimalllabels:name: mysql
spec:ports:- port: 3306targetPort: 3306selector:name: mysql