Puppet – Introduction for Beginners

In our tech world, every day new tools and framework emerge to help us in our live.One of them is Puppet.A Configuration Management tool. This blog will be for who are trying to explore any configuration management tool or someone who is hearing a name puppet for the first time.Lets us explore what Puppet is actually. Why we need it, and how it works.

What is Configuration Management Tool?

Configuration management (CM) is a systems engineering process for establishing and maintaining consistency of a product’s performance, functional, and physical attributes with its requirements, design, and operational information throughout its life.

In simple term, if you have 100s of the production server and you have to upgrade the OS version in all the server or you have to install new software on all systems.Any configuration change required. Basically, your system admin helps you with this.

For more on CM click here.

Puppet Intro

Puppet is a pioneering configuration automation and deployment orchestration solution for distributed apps and infrastructure.

This open source configuration management solution is built with Ruby and offers custom Domain Specific Language (DSL) and Embedded Ruby (ERB) templates to create custom Puppet language files and offers a declarative paradigm programming approach. Puppet uses an agent/master architecture—Agents manage nodes and request relevant info from masters that control configuration info.

The Puppet Enterprise product offers the following capabilities:

  • Orchestration
  • Automated provisioning
  • Configuration Automation
  • Visualization and reporting
  • Code management
  • Node management
  • Role-based access control

Pros:

  • Strong compliance automation and reporting tools.
  • Active community support around development tools and cookbooks.
  • Intuitive web UI to take care of many tasks, including reporting and real-time node management.
  • Robust, native capability to work with shell-level constructs.
  • Initial setup is smooth and supports a variety of OSs.
  • Particularly useful, stable and mature solution for large enterprises with adequate DevOps skill resources to manage a heterogeneous infrastructure.

Cons:

  • Can be difficult for new users who must learn Puppet DSL or Ruby, as advanced tasks usually require input from CLI.
  • Installation process lacks adequate error reporting capabilities.
  • Not the best solution available to scale deployments. The DSL code can grow large and complicated at a higher scale.
  • Using multiple masters complicates the management process. Remote execution can become challenging.
  • Support is more focused toward Puppet DSL over pure Ruby versions.
  • Lacks push system, so no immediate action on changes. The pulling process follows a specified schedule for tasks.

How Puppet Works

[embedyt]https://www.youtube.com/watch?v=lxJQX2ipliY[/embedyt]

Puppet works on the master-slave relationship. There will be master which handle all the changes and logging.Every client/machine have the puppet agent which are slaves.

In general, there is two type of master-slave relationship.Pull based and push-based architecture.Below are the images which will explain this architecture.

In Push configuration, the centralized server will push the changes or any action to all the nodes, but in pull based configuration node will as for new changes, and then get the changes from the centralized server.

Puppet is written in Ruby. It is available in enterprise version also.From version 2.0 it is available under Apache License.

Master server contains the manifest file, where with the Puppet declarative language/Ruby  DSL we have to write the task we have have to perform.

There are resources[services, packages etc] in Puppet, we have to define these resources in the manifest .Group of the resource is called as the class to logically combined the resources.

We often have multiple modules to logically group the manifest file.

Puppet has multiple masters to handle the failure conditions.All the agents have to sign the certificate and all change of information is over SSH , so every exchange is fully protected and authenticated.

Below is the video from Edureka , which explain and demonstrate how it works.

Alternatives of Puppet

  • Chef – Push Based master-slave architecture
  • Ansible – Push Based master-slave architecture
  • Salt Stack – Pull Based master-slave architecture
Advertisements

Spring Boot + Docker + Bit Bucket + Automate Deployment

An idea behind this blog to walk through the auto build of docker image in docker hub for Spring boot application.

Note: – This method is not production level, so use it for staging or development phase only.

(Why it is not suitable for production ?)

[As we have to push the jar to the git repository, to reduce few steps.]

Technology Stack Used

  • Spring Boot [1.4.1 Release]
  • Java 8
  • Maven 2
  • Bit Bucket
  • Docker Hub

Prerequisite

  • Docker Hub Account
  • Bit Bucket Account
  • Minimum knowledge of Spring boot and Java
  • Link Bit Bucket to Docker Hub. CLICK HERE for the reference.

Steps

  1. Create Spring boot Application Capable of creating docker image
    • Create simple spring boot application with web module.[CLICK HERE to create using spring start.io or get it from BIT-BUCKET repo (master branch)].
    • Add Simple test controller to the Spring Project or check out to the branch controller-test.
    • Add Docker support to your current spring boot application or check out to branch docker-support. [To learn how to add docker support to spring boot application you check this blog.]
  2.  Create New Repository and link for auto creation of image
    1. Go to docker hub and click on create -> create automatic build
    2. Click on create Auto-build bit-bucket
    3. Select the desired bitbucket repository
    4. Fill required information and click on create.
    5. Go to build setting and provide the branch name from which image should be created and save changes.
    6. Click on build details, it will be empty right now
    7. Make Some changes in that particular branch and push it to the Origin.
    8. Now again check the build details tab, there will be new entry populated with status queued.
    9. Wait for some time its status will change to building than to success.
    10. Now your docker image is ready to use.
  3. Test created docker image
      1. Now pull the docker image
      2. Run the docker image with command [docker run –name docker.test -d -p 8088:8080 jainamit333/docker.demo:docker-support]
      3. Navigate to http://localhost:8088/docker/test.It will show the desired result.

Now each time user push to anything to branch, new docker image will be created.

Dockerize Spring Boot Application

This blog will help the audience to enable them to create docker image from a Spring boot Application.We have created a Spring Boot with maven.

We have already created the code repository. This repository contain 3 branches

1.Master: – Vanilla Spring Boot with Web Module

2.Controller-Test: – Master with test Rest repository.

3.Docker-Support :- Added docker support to Controller-Test branch

Prerequisite

  • Spring Boot Knowledge
  • How to create simple DockerFile

Here we will see what changes are required to add docker support to Spring Boot Application. It is the changes required to create Docker-Support branch from Controller-Test branch.

Changes Required in Pom

We need to add below mention plugin in the pom.

<plugin>
   <groupId>com.spotify</groupId>
   <artifactId>docker-maven-plugin</artifactId>
   <version>0.2.3</version>
   <configuration>
      <imageName>horizon/${project.artifactId}</imageName>
      <dockerDirectory>/</dockerDirectory>
      <resources>
         <resource>
            <targetPath>/</targetPath>
            <directory>/</directory>
            <include>${project.build.finalName}.jar</include>
         </resource>
      </resources>
   </configuration>
</plugin>

Add DockerFile in the project path

FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD target/docker-0.0.1.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
EXPOSE 8080

There are two ways to create a docker image from the current source now.

1.Create docker image using maven plugin [can also be used using Jenkin worklow]

Run the command from project directory:- mvn clean package docker:build

2.Create docker image using docker build command

Run mvn install:- mvn clean install

Create docker image by executing the following command from project directory:

docker build  -t  docker.demo:latest  .