Kubernetes 上的Nacos集群搭建

官方文档

部署文档

官方Git库

实现功能

1、使用阿里云内网SLB发布应用,仅允许内网访问(使用1.4.0版本)
2、使用非default空间部署Nacos三节点集群
3、使用阿里云RDS存储数据
4、没有使用pvc

部署前准备

1、创建一个私网SLB实例
2、在RDS中创建一个数据库nacos_config,数据库初始化语句位置 https://github.com/alibaba/nacos/blob/develop/distribution/conf/nacos-mysql.sql
3、创建pluginprod命名空间

执行部署

kubectl apply -f nacos-no-pvc-slb.yaml 

nacos-no-pvc-slb.yaml

---
apiVersion: v1
kind: Service
metadata:
  name: nacos-headless
  namespace: pluginprod
  labels:
    app: nacos-headless
  annotations:
    # 指明SLB实例地址类型为私网类型
    #service.beta.kubernetes.io/alicloud-loadbalancer-address-type: intranet
    # 修改为您的私网SLB实例ID
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id: lb-2zeyabcdefg
    # 是否自动创建SLB端口监听(会覆写已有端口监听),也可手动创建端口监听
    service.beta.kubernetes.io/alicloud-loadbalancer-force-override-listeners: 'true'
spec:
  ports:
    - port: 8848
      name: server
      targetPort: 8848
    - port: 7848
      name: rpc
      targetPort: 7848
  selector:
    app: nacos
  sessionAffinity: None
  type: LoadBalancer
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nacos-cm
  namespace: pluginprod
data:
  mysql.host: "rm-2zeabcdefghijklmn.mysql.rds.aliyuncs.com"
  mysql.db.name: "nacos_config"
  mysql.port: "3306"
  mysql.user: "nacos"
  mysql.password: "passwd"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nacos
  namespace: pluginprod
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-headless
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: k8snacos
          imagePullPolicy: Always
          image: nacos/nacos-server:latest
          resources:
            requests:
              memory: "2Gi"
              cpu: "500m"
          ports:
            - containerPort: 8848
              name: client
            - containerPort: 7848
              name: rpc
          env:
            - name: NACOS_REPLICAS
              value: "3"
            - name: MYSQL_SERVICE_HOST
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.host
            - 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: MODE
              value: "cluster"
            - name: NACOS_SERVER_PORT
              value: "8848"
            - name: PREFER_HOST_MODE
              value: "hostname"
            - name: NACOS_SERVERS
              value: "nacos-0.nacos-headless.pluginprod.svc.cluster.local:8848 nacos-1.nacos-headless.pluginprod.svc.cluster.local:8848 nacos-2.nacos-headless.pluginprod.svc.cluster.local:8848"
  selector:
    matchLabels:
      app: nacos

你可能感兴趣的:(Kubernetes 上的Nacos集群搭建)