Kubernetes service discovery with Zookeeper¶
In Kubernetes-based containerized platforms, service discovery mechanisms allow microservices to find and communicate with each other. When using Dubbo (a high-performance RPC framework) within a Kubernetes cluster, Zookeeper typically functions as the registration center for these services[400-devops-06-kubernetes-k8s-paas-05k8scicd.md][400-devops-06-kubernetes-k8s-paas-05k8scicd.md].
Architecture and Deployment Strategy¶
In a typical Dubbo/K8s architecture, the microservices (Providers and Consumers) are deployed as stateless Pods within the cluster.[400-devops-06-kubernetes-k8s-paas-05k8scicd.md][400-devops-06-kubernetes-k8s-paas-05k8scicd.md] However, Zookeeper is a stateful service, often leading operators to deploy the Zookeeper cluster outside of the Kubernetes cluster to ensure stability and persistent storage^[400-devops-06-kubernetes-k8s-paas-05k8scicd.md].
- Zookeepers: Acts as the registry center; configured as a cluster (e.g., 3 nodes) with Leader election^[400-devops-06-kubernetes-k8s-paas-05k8scicd.md].
- Dubbo Services: Deployed inside K8s. They register themselves to the external Zookeeper upon startup^[400-devops-06-kubernetes-k8s-paas-05k8scicd.md].
- Ingress: External traffic is routed via Ingress to the Consumer service (often a web frontend), which then queries Zookeeper to locate Provider services^[400-devops-06-kubernetes-k8s-paas-05k8scicd.md].
Configuration and Registration¶
Dubbo services connect to Zookeeper using a specific connection string format in their configuration (typically dubbo.registry.address), which lists the Zookeeper hosts and ports^[400-devops-06-kubernetes-k8s-paas-05k8scicd.md].
Example configuration syntax:
zookeeper://zk1.od.com:2181?backup=zk2.od.com:2181,zk3.od.com:2181^[400-devops-06-kubernetes-k8s-paas-05k8scicd.md]
Once the connection is established, the directory structure in Zookeeper will reflect the registered services. For instance, connecting via a Zookeeper client (zkCli.sh) will display the services under the /dubbo path^[400-devops-06-kubernetes-k8s-paas-05k8scicd.md].
Monitoring¶
To visually verify that services have registered with Zookeeper (without using command-line tools), a Dubbo Monitor can be deployed^[400-devops-06-kubernetes-k8s-paas-05k8scicd.md]. This tool connects to the Zookeeper registry and provides a UI to list active applications and dependencies^[400-devops-06-kubernetes-k8s-paas-05k8scicd.md].
Sources¶
400-devops-06-kubernetes-k8s-paas-05k8scicd.md