• k8s部署nacos集群(外接mysql数据库)


    1.首先部署mysql

    version: "3"
    services:
      mysql:
        restart: always
        container_name: mysql
        image: 'nacos/nacos-mysql:5.7' #使用的镜像
        restart: always
        volumes:
          - ${PWD}/mysql/mysql:/var/lib/mysql  #挂载目录,持久化存储
          - /etc/localtime:/etc/localtime:ro
        ports:
          - '3306:3306'
        environment:
          TZ: Asia/Shanghai
          MYSQL_ROOT_PASSWORD: ******   #设置root用户的密码
        user: root
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    2.创建nacos名称空间

    kubectl create ns nacos
    #cat nacos.yaml
    
    ---
    kind: StatefulSet
    apiVersion: apps/v1
    metadata:
      name: nacos
      namespace: nacos
      labels:
        k8s.kuboard.cn/name: nacos
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: nacos
      template:
        metadata:
          creationTimestamp: null
          labels:
            app: nacos
          annotations:
            pod.alpha.kubernetes.io/initialized: 'true'
        spec:
          containers:
            - name: k8snacos
              image: 'nacos/nacos-server:1.4.2'
              ports:
                - name: client
                  containerPort: 8848
                  protocol: TCP
                - name: client-rpc
                  containerPort: 9848
                  protocol: TCP
                - name: raft-rpc
                  containerPort: 9849
                  protocol: TCP
                - name: old-raft-rpc
                  containerPort: 7848
                  protocol: TCP
              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: MYSQL_SERVICE_DB_PARAM
                  value: >-
                    characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
                - 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
              resources:
                limits:
                  memory: 1Gi
                requests:
                  cpu: 500m
                  memory: 512Mi
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
              imagePullPolicy: IfNotPresent
          restartPolicy: Always
          terminationGracePeriodSeconds: 30
          dnsPolicy: ClusterFirst
          securityContext: {}
          affinity:
            podAntiAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                - labelSelector:
                    matchExpressions:
                      - key: app
                        operator: In
                        values:
                          - nacos
                  topologyKey: kubernetes.io/hostname
          schedulerName: default-scheduler
      serviceName: nacos-headless
      podManagementPolicy: OrderedReady
      updateStrategy:
        type: RollingUpdate
        rollingUpdate:
          partition: 0
      revisionHistoryLimit: 10
    
    ---
    kind: Service
    apiVersion: v1
    metadata:
      name: nacos-headless
      namespace: nacos
      labels:
        app: nacos-headless
    spec:
      ports:
        - name: server
          protocol: TCP
          port: 8848
          targetPort: 8848
        - name: client-rpc
          protocol: TCP
          port: 9848
          targetPort: 9848
        - name: raft-rpc
          protocol: TCP
          port: 9849
          targetPort: 9849
        - name: old-raft-rpc
          protocol: TCP
          port: 7848
          targetPort: 7848
      selector:
        app: nacos
      clusterIP: None
      clusterIPs:
        - None
      type: ClusterIP
      sessionAffinity: None
    
    ---
    kind: Ingress
    apiVersion: networking.k8s.io/v1
    metadata:
      name: nacos
      namespace: nacos
      labels:
        k8s.kuboard.cn/name: nacos
    spec:
      ingressClassName: nginx
      rules:
        - host: nacos-dev.sisensing.com
          http:
            paths:
              - path: /
                pathType: Prefix
                backend:
                  service:
                    name: nacos-headless
                    port:
                      number: 8848
    
    ---
    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: nacos-cm
      namespace: nacos
    data:
      mysql.db.name: nacos_devtest
      mysql.host: 192.168.100.117
      mysql.password: ******
      mysql.port: '3306'
      mysql.user: nacos
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182

    直接访问即可

  • 相关阅读:
    STM32 TIM(一)定时中断
    【算法】折半查找
    使用VS2022连接openEuler虚拟机失败
    Swagger学习
    设备驱动理论详解,Linux操作系统原理与应用
    HDL_BITS 学习(9)
    PHP7虚拟机(PHP 7 Virtual Machine)(转载)
    C语言中常用的字符串处理函数(strlen、strcpy、strcat、strcmp)
    20240301-2-ZooKeeper面试题(二)
    Visual Studio复制、拷贝C++项目与第三方库配置信息到新的项目中
  • 原文地址:https://blog.csdn.net/u014692704/article/details/126460384