Skip to content

Commit

Permalink
fix: zookeeper hostname resolve
Browse files Browse the repository at this point in the history
ZooKeeper reads the list of servers in the zoo.cfg on startup and looks for its "own" entry.
It then uses this entry to determine which port and interface to listen on.
Since the provided hostname will resolve to 127.0.0.1 on this machine, ZooKeeper will listen on
the local loopback interface and therefore does not accept connections from the other ZooKeeper servers.
  • Loading branch information
maxsxu committed Feb 19, 2022
1 parent 2b7e97a commit ec88401
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions controllers/zookeepercluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,6 @@ func (r *ZookeeperClusterReconciler) createHeadlessService(zk *zookeeperv1alpha1
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Name: "client",
Port: 2181,
},
{
Name: "server",
Port: 2888,
Expand All @@ -272,7 +268,7 @@ func (r *ZookeeperClusterReconciler) createStatefulSet(zk *zookeeperv1alpha1.Zoo
generateServers := func(size int) string {
servers := []string{}
for i := 0; i < size; i++ {
servers = append(servers, fmt.Sprintf("server.%d=%s-%d.%s-headless:2888:3888;2181", i, zk.Name, i, zk.Name))
servers = append(servers, fmt.Sprintf("server.%d=%s-%d.%s-headless.%s.svc.cluster.local:2888:3888;2181", i, zk.Name, i, zk.Name, zk.Namespace))
}
return strings.Join(servers, " ")
}
Expand Down Expand Up @@ -318,7 +314,7 @@ func (r *ZookeeperClusterReconciler) createStatefulSet(zk *zookeeperv1alpha1.Zoo
return &corev1.Lifecycle{
PostStart: &corev1.LifecycleHandler{
Exec: &corev1.ExecAction{
Command: []string{"/bin/sh", "-c", "echo ${HOSTNAME##*-} > ${ZOO_DATA_DIR}/myid"},
Command: []string{"/bin/sh", "-c", "echo ${HOSTNAME##*-} > ${ZOO_DATA_DIR}/myid && sed -i -e \"s/$(hostname -f)/0.0.0.0/g\" ${ZOO_CONF_DIR}/zoo.cfg"},
},
},
}
Expand Down

0 comments on commit ec88401

Please sign in to comment.