Bundle Walk-Through

From ClusterLabs

Jump to: navigation, search

Overview

This is a walk-through for demonstrating Pacemaker's "bundle" feature.

Prerequisites

Choose what OS (including version) you wish to use on the cluster nodes and inside the containers. The cluster nodes must have Pacemaker 1.1.17 or later; the containers must have Pacemaker 1.1.12 or later (for Pacemaker Remote support), but 1.1.17 or later is highly recommended. This walk-through will use CentOS 7.3 for both (with Pacemaker 1.1.17 packages installed from RPM, for the cluster nodes); the differences for other OSes should be minor.

Configure a test cluster of at least two cluster nodes. Each should have at least 450MB free disk space.

Preparation

Repeat on every node:

# yum install docker
  • Enable docker to run at boot:
# systemctl enable --now docker
  • Pull a Docker base image for the container OS:
# docker pull centos:centos7
  • Create some infrastructure for the walk-through:
# mkdir -p /root/bundle-walk-through \
  /var/log/pacemaker/bundles/httpd-bundle-{0,1,2} \
  /var/local/containers/httpd-bundle-{0,1,2}
# for i in 0 1 2; do cat >/var/local/containers/httpd-bundle-$i/index.html <<EOF
<html>
<head><title>Bundle test</title></head>
<body>
<h1>httpd-bundle-$i @ $(hostname)</h1>
</body>
</html>
EOF
done
  • We'll use apache as an example of a service to be containerized. To enable monitoring of apache inside the container, we need a configuration to enable its server-status URL:
cat <<-END >/root/bundle-walk-through/status.conf
 <Location /server-status>
    SetHandler server-status
    Require local
 </Location>
END
  • Create a Dockerfile for the walk-through:
# cat >/root/bundle-walk-through/Dockerfile <<EOF
FROM centos:centos7

COPY status.conf /etc/httpd/conf.d/status.conf
RUN yum update -y
RUN yum install -y httpd bind-utils curl lsof wget which
RUN yum install -y pacemaker pacemaker-remote resource-agents
EOF

Build a container image

This needs to be done on every node. Once is sufficient, but you should repeat this step if you make changes to the Dockerfile.

  • Build the image:
# cd /root/bundle-walk-through
# docker rmi pcmktest:http
# docker build -t pcmktest:http .
  • If desired, verify that the image was created:
# docker images

The output should look something like:

REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
pcmktest            http                aab04ad64ab0        About a minute ago   412 MB
centos              centos7             98d35105a391        12 days ago          192 MB
  • You may encounter a docker "waiting for lo to become free" bug. Reboot the node to avoid this possibility.

Configure the cluster

  • From any one node, start the cluster, and configure a bundle using the test image. Replace the IP address with something appropriate (three sequential IPs need to be available):
# pcs cluster start --all --wait
# cibadmin --modify --allow-create --scope resources -X '<bundle id="httpd-bundle">
  <docker image="pcmktest:http" replicas="3" options="--log-driver=journald" />
  <network ip-range-start="192.168.122.131" host-interface="eth0" host-netmask="24">
    <port-mapping id="httpd-port" port="80"/>
  </network>
  <storage>
    <storage-mapping id="httpd-root"
      source-dir-root="/var/local/containers"
      target-dir="/var/www/html"
      options="rw"/>
    <storage-mapping id="httpd-logs"
      source-dir-root="/var/log/pacemaker/bundles"
      target-dir="/etc/httpd/logs"
      options="rw"/>
  </storage>
  <primitive class="ocf" id="httpd" provider="heartbeat" type="apache">
    <instance_attributes id="httpd-attrs">
      <nvpair id="httpd-attrs-statusurl" name="statusurl" value="http://localhost/server-status"/>
    </instance_attributes>
    <operations>
      <op id="httpd-monitor" name="monitor" interval="30s"/>
    </operations>
  </primitive>
</bundle>'

or with recent enough pcs, the latter part could be achieved (as conveniently obtained with recent enough clufter) with:

# pcs cluster cib tmp-cib.xml
# cp tmp-cib.xml tmp-cib.xml.deltasrc
# pcs -f tmp-cib.xml resource bundle create httpd-bundle \
    container docker image=pcmktest:http replicas=3 \
    options=--log-driver=journald \
    network ip-range-start=192.168.122.131 host-interface=eth0 \
    host-netmask=24 port-map id=httpd-port port=80 \
    storage-map id=httpd-root source-dir-root=/var/local/containers \
    target-dir=/var/www/html options=rw \
    storage-map id=httpd-logs source-dir-root=/var/log/pacemaker/bundles \
    target-dir=/etc/httpd/logs options=rw
# pcs -f tmp-cib.xml resource create httpd ocf:heartbeat:apache \
    statusurl=http://localhost/server-status bundle httpd-bundle
# pcs cluster cib-push tmp-cib.xml diff-against=tmp-cib.xml.deltasrc
  • Test away. Three containers should come up, and apache should be reachable at the specified IPs. This feature is experimental, and not all things you'd expect to do with a regular resource are implemented for bundles yet. You can also modify the bundle configuration to try different values. The docker instances will be named like httpd-bundle-docker-0, so you can use standard docker commands with that (e.g. docker inspect or docker exec).
Personal tools