乐趣区

关于java:kubernetes-环境安装Nacos集群

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 后盾治理拜访地址:

http://demo.nacos.com/nacos

本文由博客群发一文多发等经营工具平台 OpenWrite 公布

退出移动版