k8s 部署Nacos集群

会挽雕弓如满月,西北望,射天狼。这篇文章主要讲述k8s 部署Nacos集群相关的知识,希望能为你提供帮助。
云环境可以使用云盘或者RDS做为共享存储
一、配置NFS 1、节点ip

31_NFS-SERVER 集群 KM01192.168.1.31 KM02192.168.1.32 node01192.168.1.71 node02192.168.1.72

2、创建目录、配置
mkdir -p /data/nfs-share/mysql mkdir -p /data/nacos/ chmod 777 /data[root@km01 nfs-share]# vim /etc/exports /data/nfs-share/ *(rw,sync,no_root_squash) /data/nacos/ *(rw,sync,no_root_squash)

3、启动
exportfs -r systemctl start nfs systemctl enable nfs

二、配置nacos 1、 下载文件及目录结构
[root@km01 ~]# yum install git -y [root@km01 ~]# git clone https://github.com/nacos-group/nacos-k8s.git[root@km01 deploy]# tree ./ ./ ├── ceph │├── pvc.yaml │└── sc.yaml ├── mysql │├── mysql-ceph.yaml │├── mysql-local.yaml │└── mysql-nfs.yaml ├── nacos │├── nacos-nodeport.yaml │├── nacos-no-pvc-ingress.yaml │├── nacos-pvc-ceph.yaml │├── nacos-pvc-nfs.yaml │└── nacos-quick-start.yaml └── nfs ├── class.yaml ├── deployment.yaml └── rbac.yaml

2、配置nfs-provisioner
cd ./nfs [root@km01 nfs]# ls class.yamldeployment.yamlrbac.yamlvim deployment.yaml env: - name: PROVISIONER_NAME value: fuseim.pri/ifs - name: NFS_SERVER value: 192.168.1.31#NFS-server - name: NFS_PATH value: /data/nfs-share#NFS 目录 volumes: - name: nfs-client-root nfs: server: 192.168.1.31#NFS-server path: /data/nfs-share#NFS 目录[root@km01 nfs]# kubectl apply -f . storageclass.storage.k8s.io/managed-nfs-storage unchanged serviceaccount/nfs-client-provisioner unchanged deployment.apps/nfs-client-provisioner unchanged clusterrole.rbac.authorization.k8s.io/nfs-client-provisioner-runner unchanged clusterrolebinding.rbac.authorization.k8s.io/run-nfs-client-provisioner unchanged role.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner unchanged rolebinding.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner unchanged

3、查看 nfs-provisioner
[root@km01 nacos]# kubectl get pod -l app=nfs-client-provisioner NAMEREADYSTATUSRESTARTSAGE nfs-client-provisioner-9d8f7f9c5-8d2qh1/1Running097m

三、部署mysql 1、部署
kubectl apply -f ./mysql-nfs.yaml

#yaml文件
[root@km01 mysql]# cat mysql-nfs.yaml apiVersion: v1 kind: ReplicationController metadata: name: mysql labels: name: mysql spec: replicas: 1 selector: name: mysql template: metadata: labels: name: mysql spec: containers: - name: mysql image: nacos/nacos-mysql:5.7#镜像版本 ports: - containerPort: 3306 volumeMounts: - name: mysql-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" volumes: - name: mysql-data nfs: server: 192.168.1.31 path: /data/nfs-share/mysql#挂载至NFS目录 --- apiVersion: v1 kind: Service metadata: name: mysql labels: name: mysql spec: ports: - port: 3306#svc 端口 targetPort: 3306 #容器端口 selector: name: mysql

2、查看mysql状态
[root@km01 mysql]# kubectl get pods -o wide NAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATES busybox1/1Running2159m10.244.1.11km01< none> < none> mysql-x6slw1/1Running083m10.244.3.7km02< none> < none> [root@km01 mysql]# kubectl get svc NAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGE kubernetesClusterIP10.0.0.1< none> 443/TCP7d9h mysqlClusterIP10.0.0.245< none> 3306/TCP89m

四、部署nacos应用 1、修改配置文件
vim nacos-pvc-nfs.yaml
[root@km01 nacos]# cat nacos-pvc-nfs.yaml --- apiVersion: v1 kind: Service metadata: name: nacos-headless labels: app: nacos annotations: service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" spec: ports: - port: 8848 name: server targetPort: 8848#此处注意 ## 兼容1.4.x版本的选举端口 clusterIP: None selector: app: nacos --- apiVersion: v1 kind: ConfigMap metadata: name: nacos-cm data:#数据库参数 mysql.db.name: "nacos_devtest" mysql.port: "3306" mysql.user: "nacos" mysql.password: "nacos" --- apiVersion: apps/v1 kind: StatefulSet metadata: name: nacos spec: serviceName: nacos-headless replicas: 3 template: metadata: labels: app: nacos annotations: pod.alpha.kubernetes.io/initialized: "true" spec: affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: "app" operator: In values: - nacos topologyKey: "kubernetes.io/hostname" serviceAccountName: nfs-client-provisioner initContainers: - name: peer-finder-plugin-install image: nacos/nacos-peer-finder-plugin:1.1 imagePullPolicy: Always volumeMounts: - mountPath: /home/nacos/plugins/peer-finder name: data subPath: peer-finder containers: - name: nacos imagePullPolicy: Always image: nacos/nacos-server:latest resources: requests: memory: "2Gi"#硬件配置 cpu: "500m" ports: - containerPort: 8848 name: client-port env: - name: NACOS_REPLICAS value: "3" - name: SERVICE_NAME value: "nacos-headless" - name: DOMAIN_NAME value: "cluster.local" - name: POD_NAMESPACE valueFrom: fieldRef: apiVersion: v1 fieldPath: metadata.namespace - name: MYSQL_SERVICE_DB_NAME valueFrom: configMapKeyRef: name: nacos-cm key: mysql.db.name - name: MYSQL_SERVICE_PORT valueFrom: configMapKeyRef: name: nacos-cm key: mysql.port - name: MYSQL_SERVICE_USER valueFrom: configMapKeyRef: name: nacos-cm key: mysql.user - name: MYSQL_SERVICE_PASSWORD valueFrom: configMapKeyRef: name: nacos-cm key: mysql.password - name: NACOS_SERVER_PORT value: "8848" - name: NACOS_APPLICATION_PORT value: "8848" - name: PREFER_HOST_MODE value: "hostname" volumeMounts: - name: data mountPath: /home/nacos/plugins/peer-finder subPath: peer-finder - name: data mountPath: /home/nacos/data subPath: data - name: data mountPath: /home/nacos/logs subPath: logs volumeClaimTemplates: - metadata: name: data annotations: volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" spec: accessModes: [ "ReadWriteMany" ] resources: requests: storage: 20Gi selector: matchLabels: app: nacos

2、nodeport暴露端口,用于外部访问
[root@km01 nacos]# vim nacos-nodeport.yaml apiVersion: v1 kind: Service metadata: name: nacos-nodeport labels: app: nacos-nodeport spec: type: NodePort ports: - name: nacos port: 8848 targetPort: 8848 nodePort: 30000 selector: app: nacoskubectl apply ./nacos-nodeport.yaml

3、查看所有服务状态
[root@km01 nacos]# kubectl get pods -o wide NAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATES busybox1/1Running2168m10.244.1.11km01< none> < none> mysql-x6slw1/1Running093m10.244.3.7km02< none> < none> nacos-01/1Running059m10.244.2.12node01< none> < none> nacos-11/1Running059m10.244.0.11node02< none> < none> nacos-21/1Running059m10.244.3.9km02< none> < none> nfs-client-provisioner-9d8f7f9c5-8d2qh1/1Running0112m10.244.0.9node02< none> < none>

【k8s 部署Nacos集群】登陆nacos
k8s 部署Nacos集群

文章图片


    推荐阅读