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:
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 Synchronized | K8S Field | Mapped to Nacos Field |
---|---|---|
Service Name | service.metadata.name | service.name |
Pod Target Port(s) | service.ports.targetPort | instance.port |
Service Name | service.metadata.name | instance.cluster |
Service Port(s) | service.ports.port | instance.extendData<String, Object> |
Pod IP | pod.status.hostIP or service.ipFamilies | instance.ip |
Configuration
Follow the Deployment Documentation to set up the Nacos cluster.
Modify the application.properties file to enable K8S synchronization:
For applications outside the K8S cluster using the Java API, specify the kubeConfig:
Upon configuration, changes in services and instances within K8S will automatically synchronize to Nacos.