MySQL 主数据库部署
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql-master
labels:
name: mysql-master
spec:
replicas: 1
selector:
name: mysql-master
template:
metadata:
labels:
name: mysql-master
spec:
containers:
- name: master
image: xxxxx/nacos/nacos-mysql-master:latest
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-master-data
subPath: mysql-master
mountPath: /var/lib/mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "abc@123"
- name: MYSQL_DATABASE
value: "nacos_pre"
- name: MYSQL_USER
value: "nacos"
- name: MYSQL_PASSWORD
value: "abc@123"
- name: MYSQL_REPLICATION_USER
value: "nacos_ru"
- name: MYSQL_REPLICATION_PASSWORD
value: "nacos_ru"
volumes:
- name: mysql-master-data
nfs:
server: ip1
path: "/data/nfs/shared/"
---
apiVersion: v1
kind: Service
metadata:
name: mysql-master
namespace: dev
labels:
name: mysql-master
spec:
type: NodePort
ports:
- port: 3306
nodePort: 3305
targetPort: 3306
selector:
name: mysql-master
MySQL 从数据库部署
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql-slave
labels:
name: mysql-slave
spec:
replicas: 1
selector:
name: mysql-slave
template:
metadata:
labels:
name: mysql-slave
spec:
containers:
- name: slave
image: xxxxx/nacos/nacos-mysql-slave:latest
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-slave-data
subPath: mysql-slave
mountPath: /var/lib/mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "abc@123"
- name: MYSQL_REPLICATION_USER
value: "nacos_ru"
- name: MYSQL_REPLICATION_PASSWORD
value: "nacos_ru"
volumes:
- name: mysql-slave-data
nfs:
server: ip1
path: "/data/nfs/shared/"
---
apiVersion: v1
kind: Service
metadata:
name: mysql-slave
namespace: dev
labels:
name: mysql-slave
spec:
type: NodePort
ports:
- port: 3306
nodePort: 3307
targetPort: 3306
selector:
name: mysql-slave
nacos部署
apiVersion: v1
kind: Service
metadata:
namespace: dev
name: nacos-headless
labels:
app: nacos-headless
spec:
type: NodePort
ports:
- port: 8848
name: server
nodePort: 9048
targetPort: 8848
selector:
app: nacos
---
apiVersion: v1
kind: ConfigMap
metadata:
namespace: namespace_name
name: nacos-cm
data:
mysql.master.db.name: "nacos_pre"
mysql.master.port: "3306"
mysql.slave.port: "3306"
mysql.master.user: "nacos"
mysql.master.password: "ecidi@2019+Ecidi@2019"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
namespace: namespace_name
name: nacos
spec:
serviceName: nacos-headless
replicas: 1
template:
metadata:
labels:
app: nacos
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- nacos-headless
topologyKey: "kubernetes.io/hostname"
containers:
- name: k8snacos
imagePullPolicy: Always
image: xxxxxx/nacos/nacos-server:latest
resources:
requests:
memory: "2Gi"
cpu: "500m"
ports:
- containerPort: 8848
name: client
env:
- name: NACOS_REPLICAS
value: "1"
- name: MYSQL_MASTER_SERVICE_DB_NAME
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.master.db.name
- name: MYSQL_MASTER_SERVICE_PORT
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.master.port
- name: MYSQL_SLAVE_SERVICE_PORT
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.slave.port
- name: MYSQL_MASTER_SERVICE_USER
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.master.user
- name: MYSQL_MASTER_SERVICE_PASSWORD
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.master.password
- name: NACOS_SERVER_PORT
value: "8848"
- name: PREFER_HOST_MODE
value: "hostname"
- name: MODE
value: standalone # 此处设置是否为单机部署
- name: NACOS_SERVERS
value: "ip+portt" #此处根据实际情况修改
volumeMounts:
- name: nacos-data
subPath: nacos-data-standalone
mountPath: /home/nacos/data
- name: nacos-logs
subPath: nacos-logs-standalone
mountPath: /home/nacos/logs
volumes:
- name: nacos-data
nfs:
server: ip1
path: "/data/nfs/shared"
- name: nacos-logs
nfs:
server: ip1
path: "/data/nfs/shared"
selector:
matchLabels:
app: nacos