Background:

NACOS was built according to Kubernetes 1.20.5, and the NACOS service was integrated in the Kubernetes cluster. Want to experience the registration and discovery function of the service. Of course, I also want to experience all kinds of Sentinel integration, which is the complete experience of Spring Cloud Alibaba family bucket…… Take it one step at a time lol. Let’s start with service registration and discovery. Special thanks to https://blog.didispace.com/spring-cloud-alibaba-1/, program apes DD series inadvertently see, yesterday is very good, has been collection.

Maven packages and builds the IMAGE IMAGE of the application

Note: the following maven build process packaging basic copy from https://blog.didispace.com/spring-cloud-alibaba-1/. So don’t do the code porter. Project demo code can go to the program ape DD big guy’s github to download.

Alibaba-Nacos-Discovery-Client-Common for Service Consumers Alibaba-Nacos-Discovery-Client-Common for Service Consumers Alibaba-Nacos-Discovery-Client-Common for Service Consumers

1. Build Alibaba-Nacos-Discovery – Server Image

Well, just to highlight the service provider! This is……

Because my personal packaging test is going to be used in a Kubernets cluster, and in the same namespace as the Nacos service. So I’m using the internal service name here to connect to Nacos. Alibaba-nacos-discovery-server-0.0.1-snapshot.jar is generated in the target directory of the package package.



Upload the package to the server, rename it app.jar, and reuse Dockerfile

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD app.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

Pack the image, the image uploaded to the mirror warehouse (personal use of Tencent cloud private warehouse, of course, you can also install Harbor warehouse).

MV alibaba-nacos-discovery-server-0.0.1-snapshot.jar app.jar docker build-t Ccr.ccs.tencentyun.com/XXXX/alibaba-nacos-discovery-server:0.1. Docker push ccr.ccs.tencentyun.com/XXXX/alibaba-nacos-discovery-server:0.1

2. Build Libaba-Nacos-Discovery – Client-Common Image

The basic steps are the same as in the previous step:

Kubernetes cluster deployment service

1. The deployment of alibaba – nacos – discovery – server

cat alibaba-nacos-discovery-server.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: alibaba-nacos-discovery-server
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  selector:
    matchLabels:
      app: alibaba-nacos-discovery-server
  template:
    metadata:
      labels:
        app: alibaba-nacos-discovery-server
    spec:
      containers:
        - name: talibaba-nacos-discovery-server
          image: ccr.ccs.tencentyun.com/XXXX/alibaba-nacos-discovery-server:0.1
          ports:
            - containerPort: 8001
          resources:
            requests:
              memory: "256M"
              cpu: "250m"
            limits:
              memory: "512M"
              cpu: "500m" 
      imagePullSecrets:                                              
        - name: tencent
---

apiVersion: v1
kind: Service
metadata:
  name: alibaba-nacos-discovery-server
  labels:
    app: alibaba-nacos-discovery-server
spec:
  ports:
  - port: 8001
    protocol: TCP
    targetPort: 8001
  selector:
    app: alibaba-nacos-discovery-server
kubectl apply -f alibaba-nacos-discovery-server.yaml -n nacos

kubectl get pods -n nacos



If you log into the Nacos admin address, you can find Alibaba-Nacos-Discovery server registered in the service management-service list

2. The deployment of alibaba – nacos – discovery – the client – common

Consumers, consumers, consumers. I can’t remember cat alibaba-nacos-discovery-client-common.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: alibaba-nacos-discovery-common
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  selector:
    matchLabels:
      app: alibaba-nacos-discovery-common
  template:
    metadata:
      labels:
        app: alibaba-nacos-discovery-common
    spec:
      containers:
        - name: talibaba-nacos-discovery-common
          image: ccr.ccs.tencentyun.com/XXXX/alibaba-nacos-discovery-client-common:0.1
          ports:
            - containerPort: 9000
          resources:
            requests:
              memory: "256M"
              cpu: "250m"
            limits:
              memory: "512M"
              cpu: "500m" 
      imagePullSecrets:                                              
        - name: tencent
---

apiVersion: v1
kind: Service
metadata:
  name: alibaba-nacos-discovery-common
  labels:
    app: alibaba-nacos-discovery-common
spec:
  ports:
  - port: 9000
    protocol: TCP
    targetPort: 9000
  selector:
    app: alibaba-nacos-discovery-common
kubectl apply -f alibaba-nacos-discovery-client-common.yaml -n nacos

At this time, there should be Alibaba-Nacos-Discovery – Client-Common service registered on the Nacos management page.

3. Change Alibaba-Nacos-Discovery – Server copy number verification service

Studying the https://blog.didispace.com/spring-cloud-alibaba-1/ he launched two alibaba – nacos – discovery – server instance, well two service providers. To verify the basic functionality of nacos to bring services online and offline. I’m also going to expand it and catch up on the scale command

kubectl scale deployment/alibaba-nacos-discovery-server --replicas=2 -n nacos



The previous access to alibaba-nacos-discovery-server service is only 10.0.5.120 IP, After deployment expansion, access to Alibaba-Nacos-Discovery-Client-Common (consumer) puts back the two IPs of the two service providers in rotation.



Observe the number of instances of alibaba-nacos-discovery-server in the Nacos admin web page, the number of instances of alibaba-nacos-discovery-server, and the number of instances of health have all been changed to 2:



Click on the Alibaba-Nacos-Discovery – Server service for details. Well, the details of two instances appear under the cluster.



Here’s a feature I’d like to try out when I see cluster instance configuration:



Access the 10.5.208 example again after logging off. (10.0.5.120)



Restore instance access service provider 10.5.208. Click online and do nothing else. Continuing access to consumer applications should have the same polling weight for both IPs:



Keep it simple. Many a little makes a mickle……..

By the way, add the subscriber list haha, this place to enter no select box. Good bother to mind….