Skip to content

Commit abfd2b8

Browse files
committed
Adds ability to optionally add agents for docker examples
* Previously the documentation detailed instructions for how to add agents to a docker example cluster. This adds a script to do the dirty work.
1 parent f81a635 commit abfd2b8

File tree

2 files changed

+77
-7
lines changed

2 files changed

+77
-7
lines changed

Diff for: documentation/docker_examples.md

+38-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
## Docker Based Examples
22
This module provides docker compose files for the various architectures for experimentation purposes. This gives you the ability to stand up an entire PE stack in order to learn how this module and DR works. If you have docker and docker-compose you can start up a full Puppet architecture with a single command. Please note that Puppet does not support PE on containers in production.
33

4-
In order to decouple Bolt from a dev system, a special bolt container is created that will run all the bolt commands. This is
5-
required to achieve maximum portability. Should you want to run bolt commands against the PE stack you must
6-
first login to this bolt container via ssh, docker or docker-compose.
7-
8-
Example: `docker-compose run --entrypoint=/bin/bash bolt`
9-
104
### Requirements
115
To run the container based examples you will need the following requirements:
126

137
1. Docker
148
2. Docker compose
9+
3. Bolt 3.18+
1510
3. realpath (brew install coreutils on mac)
1611
4. 16GB memory, 24GB+ for XL and XL-DR architectures
1712
5. CPU with many cores (Tested with Core i7 6700)
@@ -46,6 +41,8 @@ In order to stop and remove the containers you will need to perform the followin
4641
2. `cd <chosen architecture>`
4742
3. docker-compose down
4843

44+
Alternative you can run something similar like: `docker-compose --project-directory=large down`
45+
4946
### Logging into the console
5047
You can login to the PE Console after successful install. However, first you will need to
5148
grab the mapped port number of the PE console. The port numbers are mapped dynamically as to not
@@ -108,6 +105,8 @@ docker inspect pe-xl-core-0.puppet.vm -f "{{json .NetworkSettings.Networks }}" |
108105
}
109106
```
110107

108+
You can also run `docker inspect pe-xl-core-0.puppet.vm -f "{{json .HostConfig.NetworkMode }}" | sed -e 's/^"//' -e 's/"$//'`
109+
111110
**NOTE** In these example you may see the use of `jq`. This is a [cli utility for parsing JSON](https://stedolan.github.io/jq/). I recommend installing it. As a alternative you can pipe output to `python -m json.tool`.
112111

113112
### Starting agent containers
@@ -122,8 +121,38 @@ Example:
122121
For most tasks these images are great. However, if you wish to use puppet orchestrator with the pcp transport. The one requirement is that all images used must be systemd aware, otherwise pxp will not start. If you do not plan on using pcp
123122
there is no need for containers with systemd.
124123

125-
At this time we have not added documention for starting a container with systemd. Instructions coming soon.
124+
You can use the the custom image `pe-base` built with the docker cluster named pe-base. This is a centos:7 image that you can use to generate tens or hundreds of agents. (Resources permitting). You will also want to run the docker run command with additonal flags.
125+
126+
`docker run -d -t --hostname=pe-std-agent1.puppet.vm --network=pe-std_default --privileged --label=pe-std-agent,docker-example-agent" -v /sys/fs/cgroup:/sys/fs/cgroup:ro pe-base"`
127+
128+
Once you have created the container you will obviously want to install the puppet agent
129+
130+
`docker exec -ti $CONTAINER_ID sh -c "curl -k https://${PE_SERVER}:8140/packages/current/install.bash | bash && puppet agent -t"`
131+
132+
Accept the cert in the console and run the puppet agent again on the agent container.
126133

134+
Login interactively if you wish: `docker exec -ti $CONTAINER_ID /bin/bash`
135+
136+
Take a look at the spec/docker/Dockerfile for examples of how to setup systemd in a container.
137+
138+
139+
### Cleaning up
140+
Before you run docker-compose down inside the cluster type directory you will need to stop and remove
141+
all the agent containers if created.
142+
143+
This can be done like so:
144+
145+
```bash
146+
# base name is the name of the primary hostname without domain
147+
PE_CLUSTER_TYPE=standard
148+
BASE_NAME=pe-std
149+
docker stop $(docker ps -q -f label="${BASE_NAME}-agent")
150+
docker rm $(docker ps -a -q -f label="${BASE_NAME}-agent")
151+
# The docker-compose down command cannot be run until the agents have been removed
152+
cd spec/docker/${PE_CLUSTER_TYPE}
153+
docker-compose down
154+
155+
```
127156

128157
### Other notes
129158
1. The install plan is not fully idempotent.
@@ -134,3 +163,5 @@ At this time we have not added documention for starting a container with systemd
134163
6. You can use top to view all the processes being run in the containers.
135164
7. Docker will use the privilege mode option when running these examples (systemd support)
136165
8. Systemd is running inside these containers! The real systemd, not the fake one.
166+
167+
If you see errors regarding peadmin::puppet_runonce, just run the install or upgrade script again. Might have to perform multiple times for resource constrained docker hosts.

Diff for: spec/docker/setup-agents.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
# Purpose: Create container agents for docker examples
3+
PE_SERVER=$1
4+
MAX_AGENTS="${2:-5}"
5+
if [[ -z $PE_SERVER ]]; then
6+
echo "No pe server provided, please provide the fqdn of your primary servername"
7+
echo "Example usage: $0 pe-std.puppet.vm [num agent containers]"
8+
echo "The default number of agent containers is 5"
9+
exit 1
10+
fi
11+
SRV_CMD="echo ${PE_SERVER} | cut -d. -f1"
12+
BASE_NAME=$(eval $SRV_CMD)
13+
DOCKER_NETWORK=$(docker inspect ${PE_SERVER} -f "{{json .HostConfig.NetworkMode }}" | sed -e 's/^"//' -e 's/"$//')
14+
if [[ -z $DOCKER_NETWORK ]]; then
15+
echo "docker network not found for ${PE_SERVER}, exiting"
16+
exit 1
17+
fi
18+
# start loop here
19+
for (( i=1; i<=$MAX_AGENTS; i++ ))
20+
do
21+
# need a way better way come up with a unique hostname
22+
AGENT_HOSTNAME="${BASE_NAME}-agent-${i}.puppet.vm"
23+
#--name $AGENT_HOSTNAME --hostname=$AGENT_HOSTNAME could be usedbut we will get duplicate certs without cleaning on ca
24+
INSTALL_CMD="curl -k https://${PE_SERVER}:8140/packages/current/install.bash | bash"
25+
RUN_CMD="docker run -d -t --network=${DOCKER_NETWORK} --privileged --label=\"${BASE_NAME}-agent\" --label=\"docker-example-agent\" -v /sys/fs/cgroup:/sys/fs/cgroup:ro pe-base"
26+
echo RUN_CMD
27+
CONTAINER=$(eval $RUN_CMD)
28+
CONTAINER=${CONTAINER:0:12}
29+
if [[ -z $CONTAINER ]]; then
30+
echo "Container was not started for some reason"
31+
exit 1
32+
fi
33+
SETUP="docker exec -ti $CONTAINER sh -c \"${INSTALL_CMD} && puppet agent -t\""
34+
eval $SETUP
35+
CHOST=$(docker exec $CONTAINER /opt/puppetlabs/bin/puppet config print certname)
36+
# if user manually signs certs, we need to fail gracefully
37+
docker exec -ti $PE_SERVER sh -c "/opt/puppetlabs/bin/puppetserver ca sign --certname ${CHOST}"
38+
docker exec -ti $CONTAINER sh -c "puppet agent -t"
39+
done

0 commit comments

Comments
 (0)