k8s部署nacos集群

2021-03-17

使用RDS(自建数据库)

mysql.host: "rm-demo.mysql.rds.aliyuncs.com"

mysql.db.name: "nacos"

mysql.port: "3306"

mysql.user: "nacos"

mysql.password: "[email protected]"

初始化数据库

wget https://raw.githubusercontent.com/alibaba/nacos/master/distribution/conf/nacos-mysql.sql

[mysql]>source nacos-mysql.sql;

使用nacos-k8s部署nacos

git clone https://github.com/nacos-group/nacos-k8s.git

cd nacos-k8s/deploy/nacos

编辑nacos-no-pvc-ingress.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: 7848

      name: rpc

      targetPort: 7848

  clusterIP: None

  selector:

    app: nacos

---

apiVersion: v1

kind: ConfigMap

metadata:

  name: nacos-cm

data:

  mysql.host: "rm-demo.mysql.rds.aliyuncs.com"

  mysql.db.name: "nacos"

  mysql.port: "3306"

  mysql.user: "nacos"

  mysql.password: "[email protected]"

---

apiVersion: apps/v1

kind: StatefulSet

metadata:

  name: nacos

spec:

  serviceName: nacos-headless

  podManagementPolicy: Parallel

  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:latest

          resources:

            requests:

              memory: "2Gi"

              cpu: "500m"

          ports:

            - containerPort: 8848

              name: client

            - containerPort: 7848

              name: rpc

          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: NACOS_SERVERS

              value: "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"

  selector:

    matchLabels:

      app: nacos

---

# ------------------- App Ingress ------------------- #

apiVersion: extensions/v1beta1

kind: Ingress

metadata:

  name: nacos-headless

  namespace: dev-arch



spec:

  rules:

  - host: nacos.demo.com

    http:

      paths:

      - path: /

        backend:

          serviceName: nacos-headless

          servicePort: server

kubectl apply -f nacos-no-pvc-ingress.yaml --namespace=dev-arch

访问nacos

Web UI: http://nacos.demo.com/nacos

账号: nacos/nacos

k8s内部服务地址:

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

查数据验证

curl 'http://nacos.demo.com/nacos/v1/cs/configs?dataId=demo&group=DEFAULT_GROUP'

参考链接

https://blog.csdn.net/iceliooo/article/details/113397537


标题:k8s部署nacos集群
作者:fish2018
地址:http://devopser.org/articles/2021/03/17/1615950424641.html