Preface: The back end partners are ready to engage in PVP battle services. The configuration center selects Ali Cloud’s Nacos service. With reference to https://nacos.io/zh-cn/docs. Since the business plans were all on the Kubernetes cluster, I simply made a demo with the reference to https://nacos.io/zh-cn/docs/use-nacos-with-kubernetes.html for them to play first. About NACOS: See https://nacos.io/zh-cn/docs/what-is-nacos.html

  • Service discovery and health monitoring: Support DNS and RPC-based service discovery. After a Service provider registers a Service using a native SDK, OpenAPI, or a separate Agent TODO, a Service consumer can use either DNS TODO or Http&API to find and discover the Service. Provides real-time health checks on services and prevents requests from being sent to unhealthy hosts or service instances
  • Dynamic configuration services: Nacos provides a unified configuration management capability that helps us manage the configuration of applications and services across all environments in a centralized, external, and dynamic manner.
  • Dynamic DNS services: NACOS supports dynamic DNS service weight routing, which makes it easy to implement mid-tier load balancing, more flexible routing strategies, traffic control, and simple DNS resolution services for data center intranets.
  • Service and its metadata management: Nacos supports the management of all services and metadata in the data center from the perspective of micro-service platform construction, including service description, life cycle, static dependency analysis of services, health status of services, traffic management of services, routing and security policies, SLAs of services, and most importantly, metrics statistics.
  • Well, there’s a list of more features……

    Nacos on Kubernetes

    For basic installation procedures, refer to https://github.com/nacos-group/nacos-k8s/blob/master/README-CN.md

    1. Create namespaces

    Of course, the first step is to create a namespace that builds the NACOS service:

    kubectl create ns nacos

    2. Git clone repository

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

    Almost all of them could not be cloned due to network reasons. I downloaded the package to the local area and then uploaded it to the server.

    3. Deploy and initialize MySQL server

    The word that produces affirmation is to use cloud business cloud database, for example Tencent cloud RDS service. Because just give the program a whole demo for them to play with, talk about MySQL integration in Kubernetes. Personal storage StorageClass is all CBS-CSI using the default Tencent Cloud. CD/nacos k8s/mysql (of course I am upload directory path is/root/nacos/nacos – k8s – master/deploy/mysql)

    1. Deploy the MySQL service

    cat pvc.yaml

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: nacos-mysql-pvc
    namespace: nacos
    spec:
    accessModes:
    - ReadWriteOnce
    resources:
      requests:
        storage: 10Gi
    storageClassName: cbs-csi
    

    The MySQL deployment file is a direct copy of mysql-ceph. Yaml with the following modification: cat mysql-.yaml

    apiVersion: v1 kind: PersistentVolumeClaim metadata: name: nacos-mysql-pvc namespace: nacos spec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi storageClassName: cbs-csi [root@sh-master-01 mysql]# cat mysql.yaml apiVersion: v1 kind: ReplicationController metadata: name: mysql labels: name: mysql spec: replicas: 1 selector: name: mysql template: metadata: labels: name: mysql spec: Containers: -name: mysql Image: nacos/nacos-mysql:5.7 ports: -containerport: 3306 Env: -name: containerPort: MYSQL_ROOT_PASSWORD value: "root" - name: MYSQL_DATABASE value: "nacos_devtest" - 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: nacos-mysql-pvc --- apiVersion: v1 kind: Service metadata: name: mysql labels: name: mysql spec: ports: - port: 3306 targetPort: 3306 selector: name: mysql
    kubectl apply -f pvc.yaml
    kubectl apply -f mysql.yaml -n nacos
    kubectl get pods -n nacos

    Wait for MySQL Pods running

    $kubectl get pods -n nacos
    NAME          READY   STATUS    RESTARTS   AGE
    mysql-hhs5q   1/1     Running   0          3h51m

    2. Enter the MySQL container and execute the initialization script

    kubectl exec -it mysql-hhs5q bash -n nacos mysql -uroot -p root ***** create database nacos_devtest; use nacos_devtest; ### I want to save the trouble, the inside of the SQL script directly copied into the... https://github.com/alibaba/nacos/blob/develop/distribution/conf/nacos-mysql.sql -- -- -- -- -- -- -- out of mysql console, and exit the container to quit; exit

    4. The deployment nacos

    From the MySQL directory CD.. /nacos cat nacos.yaml

    --- 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 - port: 7848 name: rpc targetPort: 7848 clusterIP: None selector: app: nacos --- apiVersion: v1 kind: ConfigMap metadata: name: nacos-cm data: mysql.db.name: "nacos_devtest" mysql.port: "3306" mysql.user: "nacos" mysql.password: "nacos" --- apiVersion: apps/v1 kind: StatefulSet metadata: name: 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" 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:latest resources: requests: memory: "2Gi" cpu: "500m" ports: - containerPort: 8848 name: client-port - containerPort: 7848 name: rpc env: - name: NACOS_REPLICAS value: "2" - name: SERVICE_NAME value: "nacos-headless" - name: DOMAIN_NAME value: "layabox.daemon" - name: POD_NAMESPACE valueFrom: fieldRef: apiVersion: v1 fieldPath: metadata.namespace - 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: NACOS_APPLICATION_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: [ "ReadWriteOnce" ] storageClassName: "cbs-csi" resources: requests: storage: 10Gi - metadata: name: datadir spec: accessModes: [ "ReadWriteOnce" ] storageClassName: "cbs-csi" resources: requests: storage: 10Gi - metadata: name: logdir spec: accessModes: [ "ReadWriteOnce" ] storageClassName: "cbs-csi" resources: requests: storage: 10Gi selector: matchLabels: app: nacos

    The main thing is to change StorageClassName to CBS-CSI. The AccessModes were modified, and the DOMAIN_NAME variable was modified to name the cluster suffix for itself. The simple demo will not go into detail.

    kubectl apply -f nacos.yaml -n nacos

    Waiting for service running

    5. Exposure to external services

    The proxy individual uses Traefik. In the past, the service was mapped to the outside using IngresRoute, but now it is mapped to the outside using Ingress: cat Ingress.yaml

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
    name: nacos-headless-http
    namespace: nacos
    annotations:
      kubernetes.io/ingress.class: traefik  
      traefik.ingress.kubernetes.io/router.entrypoints: web
    spec:
    rules:
    - host: nacos-server.saynaihe.com 
      http:
        paths:
        - pathType: Prefix
          path: /
          backend:
            service:
              name: nacos-headless
              port:
                number: 8848
    

    kubectl apply -f ingress.yaml

    Access:https://nacos-server.layame.com/nacosBe sure to follow the domain name with nacos. Or if it’s 404, of course you can redirect it directly to nacos from the INGRESS configuration, right? It depends on how the individual plays.



    Default username and password: nacos nacos. The first thing, of course, is to change the password……



    Well, I’ll give it to the program to play with. There’s a lot of configuration stuff left out. For example, many parameters and variables, you can refer to the official configuration to do……