3

For testing reasons, I would like, as an ordinary user, to create an entire zookeeper ensemble in a pod where all the individual zookeepers can talk to eachother.

As far as I can tell, either all the containers in a pod share the same network namespace, so they can use localhost to talk to each other, or they each have their own and can't talk to each other at all.

To be explicit, with podman, you can use this command to create a pod in with the network and uts namespaces aren't shared. (If you aren't sharing the network namespace, you should also allow the machines to have different hostnames.)

podman pod create -n zensemble --share cgroup,ipc

Is there some kind of happy middle-ground where all the containers in a pod are on a subnet and can talk to each other that way?

podman does not support Docker's --link command line option.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
Omnifarious
  • 388
  • 3
  • 13

2 Answers2

2

I faced the same problem. Since the new Zookeeper uses "Dynamic Reconfiguration", it is not that complicated, I think, to accomplish this. Just specify the ports (hpst:quorum:leaderelection;client, host defauts to 0.0.0.0) in the ZOO_SERVERS list. For the admin servers, one has to specify it per container--but that's optional.

ZOO_SERVERS="server.1=:2888:3888;2181 \
             server.2=:2889:3889;2182 \
             server.3=:2890:3890;2183"

podman pod create -n zkensemble -p 8080-8082,2181-2183

podman run --pod zkensemble --name zk1 \
    -e ZOO_MY_ID=1 \
    -e ZOO_SERVERS=$ZOO_SERVERS \
    -d zookeeper
podman run --pod zkensemble --name zk2 \
    -e ZOO_MY_ID=2 \
    -e ZOO_SERVERS=$ZOO_SERVERS \
    -e JVMFLAGS="-Dzookeeper.admin.serverPort=8081" \
    -d zookeeper
podman run --pod zkensemble --name zk3 \
    -e ZOO_MY_ID=3 \
    -e ZOO_SERVERS=$ZOO_SERVERS \
    -e JVMFLAGS="-Dzookeeper.admin.serverPort=8082" \
    -d zookeeper

Of course, if you don't want the net to be shared, there is also a solution, now complicated: all ports need to be exposed, including those for zookeeper interconnections and leader elections. However, this time all servers can stared with 8080 for the adminserver. We only need to map 8080 to different ports on the host.

IP=$(hostname -I | awk '{print $1}')

ZOO_SERVERS_1="server.1=:2888:3888;2181 \
               server.2=$IP:2889:3889;2182 \
               server.3=$IP:2890:3890;2183"
ZOO_SERVERS_2="server.1=$IP:2888:3888;2181 \
               server.2=:2889:3889;2182 \
               server.3=$IP:2890:3890;2183"
ZOO_SERVERS_3="server.1=$IP:2888:3888;2181 \
               server.2=$IP:2889:3889;2182 \
               server.3=:2890:3890;2183"

podman pod create -n zkensemble --share pid,ipc,uts

podman run --pod zkensemble --name zk1 \
    -e ZOO_MY_ID=1 \
    -e ZOO_SERVERS=$ZOO_SERVERS_1 \
    -p 2181:2181,2888:2888,3888:3888,8080:8080 \
    -d zookeeper
podman run --pod zkensemble --name zk2 \
    -e ZOO_MY_ID=2 \
    -e ZOO_SERVERS=$ZOO_SERVERS_2 \
    -p 2182:2182,2889:2889,3889:3889,8081:8080 \
    -d zookeeper
podman run --pod zkensemble --name zk3 \
    -e ZOO_MY_ID=3 \
    -e ZOO_SERVERS=$ZOO_SERVERS_3 \
    -p 2183:2183,2890:2890,3890:3890,8082:8080 \
    -d zookeeper
2

The answer I got on the #podman channel on Freenode is that this can't be done in the way I'm trying to do it. That I will have to make each zookeeper listen to a different port and they can all use localhost to talk to each other.

This will probably work in my situation, though it's complicated by the fact that Zookeeper uses three ports, only one of which is public. The others are used for leader elections and other inter-node communication.

Omnifarious
  • 388
  • 3
  • 13