部署文件目录结构

官方提供的为nacos-k8s,使用的是nfs存储和mysql pod,这里我修改为使用aws RDS mysql
image.png

数据库设置

CREATE DATABASE `nacos_config` DEFAULT CHARACTER SET utf8mb4;
use nacos_config;
source data/nacos-mysql.sql;

创建k8s资源对象

依次创建 nacos-cm、nacos-headless、nacos-statefulset、nacos-ingress

/opt/prod/discovery/nacos-eks/deploy # cat nacos-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: nacos-cm
  namespace: nacos
data:
  mysql.host: "x.me-central-1.rds.amazonaws.com"
  mysql.db.name: "nacos_config"
  mysql.port: "3306"
  mysql.user: "admin"
  mysql.password: "p"


/opt/prod/discovery/nacos-eks/deploy # cat nacos-headless.yaml
apiVersion: v1
kind: Service
metadata:
  name: nacos-headless
  namespace: nacos
  labels:
    app: nacos
  annotations:
    service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
  ports:
    - port: 8848
      name: server
      targetPort: 8848
  clusterIP: None
  selector:
    app: nacos

/opt/prod/discovery/nacos-eks/deploy # cat nacos-statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nacos
  namespace: 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: k8snacos
          imagePullPolicy: Always
          image: nacos/nacos-server:v2.0.3
          resources:
            requests:
              memory: "2Gi"
              cpu: "300m"
          ports:
            - containerPort: 8848
              name: client
          env:
            - name: NACOS_REPLICAS
              value: "3"
            - name: NACOS_AUTH_ENABLE
              value: "true"
            - 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.nacos.svc.cluster.local:8848 nacos-1.nacos-headless.nacos.svc.cluster.local:8848 nacos-2.nacos-headless.nacos.svc.cluster.local:8848"
            - name: SPRING_DATASOURCE_PLATFORM
              value: mysql
  selector:
    matchLabels:
      app: nacos

/opt/prod/discovery/nacos-eks/deploy # cat nacos-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nacos-ingress
  namespace: nacos
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip  
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nacos-headless
            port:
              number: 8848

设置登陆密码

image.png

升级到2.1.0版本

增加表字段
mysql -hx.me-central-1.rds.amazonaws.com -uadmin -pp
use nacos_config;
ALTER TABLE config_info ADD encrypted_data_key TEXT NOT NULL;
ALTER TABLE config_info_beta ADD encrypted_data_key TEXT NOT NULL;
ALTER TABLE his_config_info ADD encrypted_data_key TEXT NOT NULL;

修改镜像tag号
image: nacos/nacos-server:v2.1.0
kubectl delete -f nacos-statefulset.yaml
kubectl apply -f nacos-statefulset.yaml

EngineerLeo
598 声望38 粉丝

专注于云原生、AI等相关技术