Nacos部署
官方文档:https://nacos.io/zh-cn/docs/use-nacos-with-kubernetes.html。
拆分修改其示例的部署YAML文件nacos-pvc-nfs.yaml来使用阿里的NAS来作为PVC存储,同时测试的数据库使用在ZSSP-3的ECS上部署的单独MySQL服务。和群集主机属于同一个大的VPC下。
配置项ConfigMap
先建立Config:
vim nacos-config.yml
--- apiVersion: v1 kind: ConfigMap metadata: name: nacos-cm data: mysql.host: "172.16.1.89" mysql.port: "3306" mysql.db.name: "nacos_test" mysql.user: "nacos_test" mysql.password: "nacos_test"
kubectl create -f nacos-config.yml kubectl get configmaps
入口Headless服务
创建无头服务:
vim nacos-headless.yml
--- 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 - port: 7848 name: rpc targetPort: 7848 clusterIP: None selector: app: nacos
kubectl create -f nacos-headless.yml kubectl get svc nacos-headless
部署StatefulSet
安装Nacos:
vim nacos-pvc-nas.yml
--- apiVersion: apps/v1 kind: StatefulSet metadata: name: nacos spec: serviceName: nacos-headless replicas: 2 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" initContainers: - name: peer-finder-plugin-install image: nacos/nacos-peer-finder-plugin:1.0 imagePullPolicy: Always volumeMounts: - mountPath: "/home/nacos/plugins/peer-finder" name: plugindir containers: - name: nacos imagePullPolicy: Always image: nacos/nacos-server:1.4.1 resources: limits: memory: "2560Mi" requests: memory: "1Gi" ports: - containerPort: 8848 name: client-port - containerPort: 7848 name: rpc env: - name: NACOS_REPLICAS value: "2" - 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: MYSQL_SERVICE_HOST valueFrom: configMapKeyRef: name: nacos-cm key: mysql.host - name: NACOS_SERVER_PORT value: "8848" - name: NACOS_APPLICATION_PORT value: "8848" - name: PREFER_HOST_MODE value: "hostname" volumeMounts: - name: plugindir mountPath: /home/nacos/plugins/peer-finder - name: datadir mountPath: /home/nacos/data - name: logdir mountPath: /home/nacos/logs volumeClaimTemplates: - metadata: name: plugindir spec: accessModes: [ "ReadWriteMany" ] resources: requests: storage: 1Gi storageClassName: alicloud-nas - metadata: name: datadir spec: accessModes: [ "ReadWriteMany" ] resources: requests: storage: 1Gi storageClassName: alicloud-nas - metadata: name: logdir spec: accessModes: [ "ReadWriteMany" ] resources: requests: storage: 1Gi storageClassName: alicloud-nas selector: matchLabels: app: nacos
kubectl create -f nacos-pvc-nas.yml kubectl get statefulsets.apps nacos
Tips:数据库初始化脚本可从Github上找到,也可以在对应版本的源码包中找到 conf/ nacos-mysql.sql。
阿里Ingress入口
额外增加Ingress入口,以便配置Nacos:
初始化脚本中默认的用户密码都是nacos。