Skip to content

Instantly share code, notes, and snippets.

@metal3d
Last active December 13, 2021 12:51
Show Gist options
  • Select an option

  • Save metal3d/be1dc1849011379391c62669d61e35ee to your computer and use it in GitHub Desktop.

Select an option

Save metal3d/be1dc1849011379391c62669d61e35ee to your computer and use it in GitHub Desktop.
Start Couchbase with podman
# configuration
count=2
clustername=mycluster
admin=admin
password=password
networkname=couchbase
# create a network
podman network create ${networkname}
# and now create $count servers, decay ports
for i in $(seq $count); do
port1=$((8091 + (i-1)*4 ))
port2=$((8094 + (i-1)*4 ))
podman pod create --name server$i --network ${networkname} -p $port1-$port2:8091-8094
podman run -d --rm --name couch$i --pod server$i docker.io/couchbase:community
done
# wait for the server 1 to respond
echo "Waiting for the first server to respond..."
RESPOND=0
until [ $RESPOND == 1 ]; do
podman exec -t couch1 bash -c 'curl -sf server1:8091 -o /dev/null' && RESPOND=1
done
# now, init the cluster
podman exec -it couch1 couchbase-cli cluster-init --cluster-name=${clustername} --cluster-username=${admin} --cluster-password=${password}
# add others server to the cluster
for i in $(seq 2 $count); do
podman exec -it couch$i bash -c 'couchbase-cli server-add -c server1 -u '${admin}' -p '${password}' \
--server-add $(hostname -I) --server-add-username '${admin}' --server-add-password '${password}
done
# and rebalance
podman exec -it couch1 couchbase-cli rebalance -u ${admin} -p ${password} -c server1
echo
echo "CouchBase cluster accessible at http://localhost:8091"
echo
echo To remove all:
cat <<EOF
for i in {1..$count}; do
podman pod rm -f server\${i}
done
podman network rm ${networkname}
EOF
@metal3d
Copy link
Copy Markdown
Author

metal3d commented Dec 13, 2021

Because podman-compose wants to create a pod, Couchbase nodes cannot listen on the same port. Instead of forcing configuration on each nodes, this script create one pod per server in the same network.

@metal3d
Copy link
Copy Markdown
Author

metal3d commented Dec 13, 2021

Note: edited, I didn't add the service list to the first node, so the query view wasn't usable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment