Skip to content
Nacos 配置中心安全问题汇总及解决方案 Know more

Nacos supports synchronizing metadata from K8S service discovery

Data synchronization

Nacos monitors the changes of services and instances in K8S, obtains its service metadata, and synchronizes the change information to Nacos’ service discovery. Supports K8S version 1.22 (corresponding to K8S-Java-API version 14.0.0).The diagram is as follow:

Mapping scheme of K8S resource synchronization to Nacos resource (single-direction, Nacos resource synchronization to K8S resource to be supplemented) :

K8S Data to be synchronizedField in K8SField mapped to Nacos
service nameservice.metadata.nameservice.name
service targetPort(pod port)(multiple)service.ports.targetPortinstance.port
service nameservice.metadata.nameinstance.cluster
service port(multiple)service.ports.portinstance.extendData<String, Object>
pod ippod.status.hostIP / service.ipFamiliesinstance.ip

Configuration file

Deploy the Nacos cluster according to the deploy document

Configure the application.properties file to enable K8S synchronization:

nacos.k8s.sync.enabled=true

If you are using the Java API from an application outside the K8S cluster, you need to specify kubeConfig:

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

After configuration, services and instance changes in K8S are automatically synchronized to Nacos.