kubernetes 环境安装Nacos集群
1.nfs服务器配置
#所有k8s节点执行
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
#添加nacos、mysql-master 、mysql-slave 持久化文件夹
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 kipnode1
2.部署nfs
下载nacos k8s部署代码
git clone https://github.com/nacos-group/nacos-k8s.git
创建nacos 命名空间
kubectl create namespace nacos
创建角色
cd nacos-k8s
NS=$(kubectl config get-contexts|grep -e "^\*" |awk '{print $5}')
NAMESPACE=${NS:-nacos}
sed -i'' "s/namespace:.*/namespace: $NAMESPACE/g" ./deploy/nfs/rbac.yaml
kubectl create -f deploy/nfs/rbac.yaml
创建 ServiceAccount
和部署 NFS-Client Provisioner
修改deployment.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: nfs-client-provisioner
spec:
replicas: 1
strategy:
type: Recreate
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: kipnode1
- name: NFS_PATH
value: /usr/local/nacos/nfs-share
volumes:
- name: nfs-client-root
nfs:
server: kipnode1
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
3.部署数据库
部署主库
修改 mysql-master-nfs.yaml nfs位置
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: kipnode1
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
部署从库
修改 mysql-slave-nfs.yaml nfs位置
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: kipnode1
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
4.部署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 对Nacos动态扩容
kubectl scale sts nacos --replicas=3 -n nacos
5.创建ingress
vi ingress/nacos-ingress.yaml
---
# 创建Ingress,定义访问规则
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nacos-headless
spec:
rules:
- host: demo.nacos.com
http:
paths:
- path: /
backend:
serviceName: nacos-headless
servicePort: 8848
kubectl create -f nacos-ingress.yaml -n nacos
nacos后台管理访问地址:
本文由博客群发一文多发等运营工具平台 OpenWrite 发布