Puppet For Containerization - Sample Chapter
Puppet For Containerization - Sample Chapter
Puppet For Containerization - Sample Chapter
ee
Puppet for
Containerization
Sa
m
pl
your system.
The book will also cover use cases of deploying Puppet
C o m m u n i t y
E x p e r i e n c e
D i s t i l l e d
$ 44.99 US
28.99 UK
P U B L I S H I N G
Scott Coulton
Puppet for
Containerization
Learn about configuration management and gain complete control
of your Docker containers using Puppet
Scott Coulton
Preface
This book teaches you how to take advantage of the new benefits of containerization
systems such as Docker, Kubernetes, Docker Swarm, and Docker UCP, without
losing the panoptical power of proper configuration management. You will learn to
integrate your containerized applications and modules with your Puppet workflow.
Preface
Chapter 5, Configuring Service Discovery and Docker Networking, introduces two very
important topics when working with containers. First, we will look at service
discovery, what it is, why do we need it, and lastly, the different types of service
discovery.
Chapter 6, Multinode Applications, introduces all the skills that you've learned in the
book so far. We are really going to step it up a notch. In this chapter, we are going
to deploy four servers, and we are going to look at how to Consul cluster. In this
chapter, we are going to look at the two ways to network our containers. Firstly,
using the stand host IP network, that our Consul cluster will communicate on.
We will also install the ELK (Elasticsearch, Logstash, and Kibana) stack.
Chapter 7, Container Schedulers, covers container schedulers such as Docker Swarm
and Kubernetes. Then, we will build a dev environment containing four servers,
three cluster nodes, and a master. We will also build a Docker network and service
discovery framework.
Chapter 8, Logging, Monitoring, and Recovery Techniques, will take the environment that
we created in the last chapter and add monitoring, logging, and recovery techniques
to it. This will make our applications robust and ready for production.
Chapter 9, Best Practices for the Real World, focuses more on the best practices for
deploying Puppet itself within a containerized environment using all the new skills
that you learned in the previous chapters. By the end of this journey, readers will be
able to master Puppet and Docker and apply them in the real world.
Installing Vagrant
Installing Docker
Installing Vagrant
You may ask, why are we using Vagrant for our development environment?
Vagrant is a must-have for Puppet development. The idea that you can spin up
environments for development locally in minutes was a revolution in Vagrant's
early releases. The product has now grown in leaps and bounds, with multiple
provisioners such as Chef and Salt. Paired with multiple virtualization backends
such as VirtualBox, VMware Workstation/Fusion, KVM, and we are going to use
VirtualBox and Puppet as your provisioner.
[1]
The installation
Let's install Vagrant. Firstly, we will need our virtualization backend, so let's
download and install VirtualBox. At the time of writing, we use VirtualBox 5.0.10
r104061. If that's outdated by the time you read this book, just grab the latest version.
You can download VirtualBox from https://www.virtualbox.org/wiki/
Downloads. Choose the version for your OS, as shown in the following screenshot:
Once the package is downloaded, follow the given installation process for your OS.
VirtualBox
Follow these steps to install Vagrant on Mac OSX:
1. Go to your Downloads folder and double-click on VirtualBox.xxx.xxx.dmg.
The following installation box will pop up:
[2]
Chapter 1
The installer will then check whether the software is compatible with the Mac
OSX version.
[3]
3. After this, click on Continue. Once the check is successful, we can move on to
the next step:
4. We then choose the default location for the installation and click on Install.
5. Then, enter your admin password and click on Install Software:
[4]
Chapter 1
The installation is now complete. The following screenshot shows what the screen
looks like after completing the installation:
[5]
At the time of writing this book, we are going to use Vagrant 1.7.4; if that
is no longer the latest version, please grab the latest one. You can find this
version of Vagrant at https://www.vagrantup.com/downloads.
html. Again, download the installation package for your OS.
Vagrant
Here, we are just going to complete a standard installation. Follow these steps to
do so:
1. Go to the folder in which you downloaded vagrant.1.7.4.dmg and doubleclick on the installer. You will then get the following pop up:
2. Double-click on vagrant.pkg.
[6]
Chapter 1
[7]
[8]
Chapter 1
Vagrantfile
Now that we have a fully working Vagrant environment, we can start with and look
at how Vagrant works and how we are going to provision our machines. As this
book is not about Vagrant, we won't be writing a Vagrantfile from scratch. Instead, I
have created a Vagrantfile that we will be using throughout the book:
[9]
[ 10 ]
Chapter 1
As you can see from the preceding screenshot, the Vagrantfile is actually a Ruby file.
As it is Ruby, it opens up a world of opportunities for us to make our code elegant
and efficient. So, in this Vagrantfile, we have extracted all the low-level configurations
and replaced them with a few parameters. Why are we doing this? The reason is to
split up our logic from our configuration and also iterate our configuration in order
to stop replication of our code. So, where is all the configuration stored? The answer
is in the servers.yaml file. This is where we set the vagrant box that we want to
deploy, the number of CPUs for the box, the internal network's IP, the hostname, the
forwarded ports between the guest and host, and the RAM and shell provider for bash
commands that we need to get the environment ready for Puppet to run, for example,
downloading modules and their dependencies from the Puppet Forge:
The benefit of this approach is also that any developer using a Vagrantfile does not
need to actually modify the logic in the Vagrantfile. They only need to update the
configuration in servers.yaml. As we go through the book, we will work with the
other files in the repository, such as Puppetfile, hieradata, and manifests. Now
that we have set up our Vagrant environment, let's look at how to get our Puppet
modules from the Puppet Forge.
[ 11 ]
The Puppet Forge is a website that puppetlabs runs. It is a place where other Puppet
developers publish modules that are ready to use. You might be asking, what about
GitHub? Can't you get modules from there? Yes, you can. The difference between the
Puppet Forge and GitHub is that the Puppet Forge is the stable, releasable version of
the module, whereas GitHub is the place to contribute to the module, that is, a place
to create pull requests.
You can find the Puppet Forge at https://forge.puppetlabs.com/.
Now that we have been introduced to the Puppet Forge, let's use it to find our
Docker module that we will be using to build our environment.
We are going to use the garethr/docker Docker module, which you can
find at https://forge.puppetlabs.com/garethr/docker.
[ 12 ]
Chapter 1
Now that we have selected our module, we can move on to setting up our puppetfile:
[ 13 ]
The following screenshot is an example of what the puppetfile should look like:
Now, when we run vagrant up, r10k will pull the modules from the Puppet Forge.
We invoke r10k on line 13 of servers.yaml with the r10k puppetfile install
verbose command. The following screenshot shows the output of this command:
Now that we have our puppetfile set up, we can install Docker.
[ 14 ]
Chapter 1
Installing Docker
In this topic, we will put together all the configuration from our Vagrant repo and
knowledge of the Puppet Forge to create the Docker environment.
This will now provide us with our CentOS 7 box. Install r10k and then run Puppet
and apply the Docker class. This will take about 4 minutes depending on your laptop
and network connection. If the box was provisioned successfully, you will see the
following output:
We can also verify that the Docker installation was successful by logging in to
the box via SSH. We will do that with the vagrant ssh command. Once we are in,
we will sudo up to root (sudo -i). Now, let's just check whether Docker is installed
with the docker command.
[ 15 ]
[ 16 ]
Chapter 1
Summary
In this chapter, we covered how to create a development environment with Docker
using Puppet. We looked at how to install Vagrant and VirtualBox. Then, we looked
at the Puppet Forge, how to search for modules and their dependencies. We then
took the dependencies and mapped them to a puppetfile. We briefly touched on
r10k, which is our transport mechanism from the Puppet Forge to our environment.
Then, we built our environment with Puppet.
In the next chapter, we'll take a look at how to access Docker Hub and pull
public images.
[ 17 ]
www.PacktPub.com
Stay Connected: