Skip to content
铭师堂的云原生升级实践Know more

Nacos Supports Synchronizing Service Metadata from K8S Service Discovery

Nacos Supports Synchronization of Service Metadata from K8S Service Discovery

Data Synchronization

Nacos listens for changes in services and instances within K8S, acquiring their service metadata, and synchronizing update information to the Nacos service discovery module and instances. It supports K8S version 1.22 (corresponding to the K8S-Java-API version 14.0.0). An illustrative diagram is as follows: K8S Sync Illustration

The mapping scheme for synchronizing K8S resources to Nacos resources (unidirectional, with supplementation for Nacos resource synchronization to K8S resources pending):

K8S Data to be SynchronizedK8S FieldMapped to Nacos Field
Service Nameservice.metadata.nameservice.name
Pod Target Port(s)service.ports.targetPortinstance.port
Service Nameservice.metadata.nameinstance.cluster
Service Port(s)service.ports.portinstance.extendData<String, Object>
Pod IPpod.status.hostIP or service.ipFamiliesinstance.ip

Configuration

Follow the Deployment Documentation to set up the Nacos cluster.

Modify the application.properties file to enable K8S synchronization:

nacos.k8s.sync.enabled=true

For applications outside the K8S cluster using the Java API, specify the kubeConfig:

nacos.k8s.sync.outsideCluster=true
nacos.k8s.sync.kubeConfig=/.kube/config

Upon configuration, changes in services and instances within K8S will automatically synchronize to Nacos.