目录
一、nfs服务器配置
$ yum install -y nfs-utils
$ mkdir -p /usr/local/nacos/nfs-share
$ mkdir -p /usr/local/nacos/mysql-slave
$ mkdir -p /usr/local/nacos/mysql-master
$ chmod a+rw /usr/local/nacos
$ vi /etc/exports
/usr/local/nacos/mysql-master *(insecure,rw,async,no_root_squash)
/usr/local/nacos/mysql-slave *(insecure,rw,async,no_root_squash)
/usr/local/nacos/nfs-share *(insecure,rw,async,no_root_squash)
$ systemctl restart rpcbind.service
$ systemctl restart nfs-server.service
$ showmount -e k8s-master
二、部署NFS StorageClass
2.1 下载nacos k8s 部署代码
$ git clone https://github.com/nacos-group/nacos-k8s.git
2.2 创建nacos命名空间
$ kubectl create ns nacos
2.3 创建ServiceAccount
$ cd nacos-k8s
$ sed -i 's/namespace: default/namespace: nacos/g' deploy/nfs/rbac.yaml
2.4 部署NFS-Client Provisioner
修改deployment.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: nfs-client-provisioner
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: nfs-client-provisioner
template:
metadata:
labels:
app: nfs-client-provisioner
spec:
serviceAccount: nfs-client-provisioner
containers:
- name: nfs-client-provisioner
image: quay.io/external_storage/nfs-client-provisioner:latest
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: fuseim.pri/ifs
- name: NFS_SERVER
value: k8s-master
- name: NFS_PATH
value: /usr/local/nacos/nfs-share
volumes:
- name: nfs-client-root
nfs:
server: k8s-master
path: /usr/local/nacos/nfs-share
$ kubectl create -f deploy/nfs/deployment.yaml -n nacos
创建 NFS StorageClass
$ kubectl create -f deploy/nfs/class.yaml -n nacos
验证NFS部署成功
$ kubectl get pod -l app=nfs-client-provisioner -n nacos
NAME READY STATUS RESTARTS AGE
nfs-client-provisioner-65c7bc8d57-mcdg9 1/1 Running 0 2m26s
三、部署mysql数据库
3.1 部署主库
$ vim deploy/mysql/mysql-master-nfs.yaml
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: nacos/nacos-mysql-master:latest
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-master-data
mountPath: /var/lib/mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "root"
- name: MYSQL_DATABASE
value: "nacos_devtest"
- name: MYSQL_USER
value: "nacos"
- name: MYSQL_PASSWORD
value: "nacos"
- name: MYSQL_REPLICATION_USER
value: 'nacos_ru'
- name: MYSQL_REPLICATION_PASSWORD
value: 'nacos_ru'
volumes:
- name: mysql-master-data
nfs:
server: k8s-master
path: /usr/local/nacos/mysql-master
---
apiVersion: v1
kind: Service
metadata:
name: mysql-master
labels:
name: mysql-master
spec:
ports:
- port: 3306
targetPort: 3306
selector:
name: mysql-master
$ kubectl create -f deploy/mysql/mysql-master-nfs.yaml -n nacos
3.2 部署从库
$ vim deploy/mysql/mysql-slave-nfs.yaml
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: nacos/nacos-mysql-slave:latest
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-slave-data
mountPath: /var/lib/mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "root"
- name: MYSQL_REPLICATION_USER
value: 'nacos_ru'
- name: MYSQL_REPLICATION_PASSWORD
value: 'nacos_ru'
volumes:
- name: mysql-slave-data
nfs:
server: k8s-master
path: /usr/local/nacos/mysql-slave
---
apiVersion: v1
kind: Service
metadata:
name: mysql-slave
labels:
name: mysql-slave
spec:
ports:
- port: 3306
targetPort: 3306
selector:
name: mysql-slave
$ kubectl create -f deploy/mysql/mysql-slave-nfs.yaml -n nacos
四、部署Nacos
修改deploy/nacos/nacos-pvc-nfs.yaml
和数据库配置文件保持一致即可!
data:
mysql.master.db.name: "主库名称"
mysql.master.port: "主库端口"
mysql.slave.port: "从库端口"
mysql.master.user: "主库用户名"
mysql.master.password: "主库密码"
$ kubectl create -f deploy/nacos/nacos-pvc-nfs.yaml -n nacos
$ kubectl scale sts nacos --replicas=3 -n nacos
五、创建ingress
$ vim nacos-ingress.yaml
---
# 创建Ingress,定义访问规则
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nacos-headless
spec:
rules:
- host: nacos.lvzhenjiang.com
http:
paths:
- path: /
backend:
serviceName: nacos-headless
servicePort: 8848
$ kubectl create -f nacos-ingress.yaml -n nacos