k8s 部署 nacos 1.4.1 集群

1 篇文章 0 订阅
1 篇文章 0 订阅
根据官方提供的 yaml 增加了 mysql 地址配置

Mysql 部署

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nacos-mysql-deployment
  namespace: public
  labels:
    name: nacos-mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      name: nacos-mysql
  template:
    metadata:
      labels:
        name: nacos-mysql
    spec:
      containers:
      - name: nacos-mysql
        image: nacos/nacos-mysql:5.7
        ports:
        - containerPort: 3306
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "root"
        - name: MYSQL_DATABASE
          value: "nacos_test"
        - name: MYSQL_USER
          value: "nacos"
        - name: MYSQL_PASSWORD
          value: "nacos"
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
          subPath: mysql
          readOnly: false
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-nacos-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: nacos-mysql-svc
  namespace: public
  labels:
    name: nacos-mysql
spec:
  ports:
  - port: 3306
    targetPort: 3306
  selector:
    name: nacos-mysql 

Nacos 部署

---
apiVersion: v1
kind: Service
metadata:
  name: nacos-headless
  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
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nacos-cm
data:
  mysql.db.host: "nacos-mysql-svc.public.svc.cluster.local"
  mysql.db.name: "nacos_test"
  mysql.port: "3306"
  mysql.user: "nacos"
  mysql.password: "nacos"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nacos
spec:
  serviceName: nacos-headless
  replicas: 2
  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"
      # serviceAccountName: cephfs-provisioner
      initContainers:
        - name: peer-finder-plugin-install
          image: nacos/nacos-peer-finder-plugin:1.0
          imagePullPolicy: Always
          volumeMounts:
            - mountPath: /home/nacos/plugins/peer-finder
              name: plguindir
      containers:
        - name: nacos
          imagePullPolicy: Always
          image: nacos/nacos-server:1.4.1
          resources:
            requests:
              memory: "2Gi"
              cpu: "500m"
          ports:
            - containerPort: 8848
              name: client-port
          env:
            - name: NACOS_REPLICAS
              value: "2"
            - name: SERVICE_NAME
              value: "nacos-headless"
            - name: DOMAIN_NAME
              value: "cluster.local"
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: MYSQL_SERVICE_HOST
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.db.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: NACOS_SERVER_PORT
              value: "8848"
            - name: PREFER_HOST_MODE
              value: "hostname"
          volumeMounts:
            - name: plguindir
              mountPath: /home/nacos/plugins/peer-finder
            - name: datadir
              mountPath: /home/nacos/data
            - name: logdir
              mountPath: /home/nacos/logs
  volumeClaimTemplates:
    - metadata:
        name: plguindir
      spec:
        accessModes: [ "ReadWriteMany" ]
        storageClassName: "longhorn"
        resources:
          requests:
            storage: 5Gi
    - metadata:
        name: datadir
      spec:
        accessModes: [ "ReadWriteMany" ]
        storageClassName: "longhorn"
        resources:
          requests:
            storage: 5Gi
    - metadata:
        name: logdir
      spec:
        accessModes: [ "ReadWriteMany" ]
        storageClassName: "longhorn"
        resources:
          requests:
            storage: 5Gi
  selector:
    matchLabels:
      app: nacos

Ingress 代理

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: ingress-nginx
  name: nacos-ingress
  namespace: public
spec:
  rules:
  - host: nacos.qianyidui.com
    http:
      paths:
      - backend:
          serviceName: nacos-headless
          servicePort: server
        path: /nacos
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值