当前位置: 正能量 » 代码编程 » K8s » k8s部署3节点Naocs集群

k8s部署3节点Naocs集群

配置文件nacos-config.yaml

使用的是外部 mysql 数据库,所以没有使用官方提供的 mysql 和存储方案。

---
apiVersion: v1
data:
  MODE: cluster
  MYSQL_SERVICE_DB_NAME: nacos_db
  MYSQL_SERVICE_HOST: 172.16.0.163
  MYSQL_SERVICE_PASSWORD: MySQL密码
  MYSQL_SERVICE_PORT: '3306'
  MYSQL_SERVICE_USER: nacos
  NACOS_APPLICATION_PORT: '8848'
  NACOS_AUTH_ENABLE: 'true'
  NACOS_AUTH_IDENTITY_KEY: nacosAuthKey
  NACOS_AUTH_IDENTITY_VALUE: nacosSecurtyValue
  NACOS_AUTH_TOKEN: YjI5YTIwNDkwMGUxZmY5NjNlZTU5ZWFjMjlhZTc4OTU4YTVjNjUxOQ== #这里的token需要base64编码,且长度不低于32个字符,一般用个字符做sha1然后base64
  NACOS_AUTH_TOKEN_EXPIRE_SECONDS: '18000'
  NACOS_REPLICAS: '3'
  NACOS_SERVERS: >-
    nacos-0.nacos-headless.default.svc.cluster.local:8848
    nacos-1.nacos-headless.default.svc.cluster.local:8848
    nacos-2.nacos-headless.default.svc.cluster.local:8848
  NACOS_SERVER_PORT: '8848'
  PREFER_HOST_MODE: hostname
  SPRING_DATASOURCE_PLATFORM: mysql
kind: ConfigMap
metadata:
  name: nacos-server-config
  namespace: default

部署文件nacos-deploy.yaml

###使用自建数据库;使用Ingress发布配置后台###
---
apiVersion: v1
kind: Service
metadata:
  name: nacos-headless
  labels:
    app: nacos-headless
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - port: 8848
      name: server
      targetPort: 8848
    - port: 9848
      name: client-rpc
      targetPort: 9848
    - port: 9849
      name: raft-rpc
      targetPort: 9849
      ## 兼容1.4.x版本的选举端口
    - port: 7848
      name: old-raft-rpc
      targetPort: 7848
  selector:
    app: 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"
      containers:
        - name: nacos
          imagePullPolicy: Always
          image: registry.cn-shenzhen.aliyuncs.com/mmgg/nacos-server:v2.3.2
          resources:
            requests:
              memory: "2Gi"
              cpu: "500m"
          ports:
            - containerPort: 8848
              name: client
            - containerPort: 9848
              name: client-rpc
            - containerPort: 9849
              name: raft-rpc
            - containerPort: 7848
              name: old-raft-rpc
          envFrom:
            - configMapRef:
                name: nacos-server-config
  selector:
    matchLabels:
      app: nacos

---
# ------------------- App Ingress ------------------- #
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nacos-headless
spec:
  rules:
  - host: nacos.k8s.znl.net
    http:
      paths:
      - path: /nacos
        pathType: Prefix
        backend:
          service: 
            name: nacos-headless
            port:
              name: server
未经允许不得转载:正能量 » k8s部署3节点Naocs集群

相关文章

评论 (0)

8 + 3 =