k8s快速部署nacos单机版

一、配置文件

1.初始化数据库

wget https://raw.githubusercontent.com/alibaba/nacos/develop/distribution/conf/mysql-schema.sql
mysql -uroot -p
CREATE DATABASE IF NOT EXISTS nacos_config DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
use nacos_config;
source  /root/mysql-schema.sql;
CREATE USER 'nacos'@'%' IDENTIFIED BY 'WKjIjQZ1ub3V5qSd'; #不能包含特殊字符
GRANT ALL PRIVILEGES ON nacos_config.* TO 'nacos'@'%';
FLUSH PRIVILEGES;
exit;

2.创建nacos配置文件

apiVersion: v1
kind: ConfigMap
metadata:
  name: t1-zdbl-nacos-cm
  namespace: t1-zdbl
data:
  mysql.host: "t1-zdbl-mysql.t1-zdbl.svc.cluster.local"
  mysql.db.name: "nacos_config"
  mysql.port: "3306"
  mysql.user: "t1_zdbl_nocos"
  mysql.password: "xxxxxx"  #注意此处的密码不要包含特殊字符,否则在开启鉴权的情况下可能导致客户端连接错误,报403

3.创建nacos deploy部署文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: t1-zdbl-nacos
  namespace: t1-zdbl
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: t1-zdbl-nacos
    spec:
      containers:
        - name: k8snacos
          image: nacos/nacos-server:v2.2.0
          resources:
            requests:
              memory: "1Gi"
              cpu: "500m"
          ports:
            - containerPort: 8848
              name: client
            - containerPort: 9848
              name: client-rpc
            - containerPort: 9849
              name: raft-rpc
            - containerPort: 7848
              name: old-raft-rpc
          env:
            - name: SPRING_DATASOURCE_PLATFORM
              value: "mysql"
            - name: MYSQL_SERVICE_HOST
              valueFrom:
                configMapKeyRef:
                  name: t1-zdbl-nacos-cm
                  key: mysql.host
            - name: MYSQL_SERVICE_DB_NAME
              valueFrom:
                configMapKeyRef:
                  name: t1-zdbl-nacos-cm
                  key: mysql.db.name
            - name: MYSQL_SERVICE_PORT
              valueFrom:
                configMapKeyRef:
                  name: t1-zdbl-nacos-cm
                  key: mysql.port
            - name: MYSQL_SERVICE_USER
              valueFrom:
                configMapKeyRef:
                  name: t1-zdbl-nacos-cm
                  key: mysql.user
            - name: MYSQL_SERVICE_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: t1-zdbl-nacos-cm
                  key: mysql.password
            - name: MODE
              value: "standalone"
            - name: NACOS_SERVER_PORT
              value: "8848"
            - name: PREFER_HOST_MODE
              value: "hostname"
            - name: NACOS_AUTH_ENABLE  #开启鉴权
              value: "true"
            - name: NACOS_AUTH_IDENTITY_KEY
              value: "nacosAuthKey"
            - name: NACOS_AUTH_IDENTITY_VALUE
              value: "nacosSecurtyValue"
            - name: NACOS_AUTH_TOKEN
              value: "SecretKey012345678901234567890123456789012345678901234567890123456789"
            - name: NACOS_AUTH_TOKEN_EXPIRE_SECONDS
              value: "18000"  
  selector:
    matchLabels:
      app: t1-zdbl-nacos

4.创建nacos svc文件

apiVersion: v1
kind: Service
metadata:
  name: t1-zdbl-nacos
  namespace: t1-zdbl
  labels:
    app: t1-zdbl-nacos
spec:
  type: NodePort
  ports:
    - port: 8848
      name: server
      targetPort: 8848
      nodePort: 31048
    - port: 9848
      name: client-rpc
      targetPort: 9848
    - port: 9849
      name: raft-rpc
      targetPort: 9849
    - port: 7848
      name: old-raft-rpc
      targetPort: 7848
  selector:
    app: t1-zdbl-nacos

5.创建nacos ingress文件

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: t1-zdbl-nacos
  namespace: t1-zdbl
  annotations:
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80},{"HTTPS": 443}]'
    alb.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  ingressClassName: alb  #此处使用了阿里云的ALB Ingress,如果是其他自行替换即可
  rules:
   - host: t1-zdbl-nacos.xxxxx.com
     http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: t1-zdbl-nacos
            port:
              number: 8848

初始化数据库后直接apply以上yaml文件即可

二、可能遇到的问题

1.启动报  "Caused by: java.sql.SQLSyntaxErrorException: Unknown column ‘encrypted_data"错误

解决方法:

手动为数据库表 config_info、config_info_beta、his_config_info中需要新增字段 encrypted_data_key

ALTER TABLE table_name ADD COLUMN `encrypted_data_key` text NOT NULL COMMENT '秘钥'  #将table_name 替换为以上三个表名称

2.默认账号密码无法登录(nacos/nacos)

打开Bcrypt在线加密工具

 使用生产的结果个替换数据库password字段

 

 

 

 

 

posted @ 2023-03-01 08:43  百衲本  阅读(2127)  评论(0编辑  收藏  举报
cnblogs_post_body { color: black; font: 0.875em/1.5em "微软雅黑" , "PTSans" , "Arial" ,sans-serif; font-size: 15px; } cnblogs_post_body h1 { text-align:center; background: #333366; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 23px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h2 { text-align:center; background: #006699; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 20px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h3 { background: #2B6695; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 18px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } 回到顶部 博客侧边栏 回到顶部 页首代码 回到顶部 页脚代码