DevOps Complete Guide for Engineers
DevOps Complete Guide for Engineers
Ensure Security: Implement practices to keep 8. ELK Stack (Elasticsearch, Logstash, Kibana)
systems secure from potential threats.
Purpose: Logging and Analytics
10 Best DevOps Tools
Features: Real-time data search and analysis,
1. Jenkins log aggregation, and powerful visualization
capabilities.
Purpose: Continuous Integration and
Continuous Delivery (CI/CD) 9. Azure DevOps
8. Monitor – The DevOps workflow is observed Leverages the productivity, expedites product
at this level depending on data gathered from delivery, and skills of the employees through
consumer behavior, application efficiency, better communication and assistance,
and other sources. The ability to observe the
Reduce possibilities of errors and conflicts
complete surroundings aids teams in
meanwhile project development through
identifying bottlenecks affecting the
traceability to every small change,
production and operations teams’
performance. Employees or contributors of the project can
contribute from anywhere irrespective of the
What is a “version control system”?
different geographical locations through
this VCS,
Version control systems are a category of software For each different contributor to the project,
tools that helps in recording changes made to files by a different working copy is maintained and
keeping a track of modifications done in the code. not merged to the main file unless the
working copy is validated. The most popular
example is Git, Helix core, Microsoft TFS,
Why Version Control system is so Important?
Helps in recovery in case of any disaster or
contingent situation,
As we know that a software product is developed in Informs us about Who, What, When, Why
collaboration by a group of developers they might be changes have been made.
located at different locations and each one of them
Use of Version Control System:
contributes to some specific kind of
functionality/features. A repository: It can be thought of as a
database of changes. It contains all the edits
A version control system is a kind of software that
and historical versions (snapshots) of the
helps the developer team to efficiently communicate
project.
and manage(track) all the changes that have been
made to the source code along with the information Copy of Work (sometimes called as
like who made and what changes have been made. A checkout): It is the personal copy of all the
separate branch is created for every contributor who files in a project. You can edit to this copy,
made the changes and the changes aren’t merged without affecting the work of others and you
into the original source code unless all are analyzed as can finally commit your changes to a
soon as the changes are green signaled they merged repository when you are done making your
to the main source code. It not only keeps source changes.
code organized but also improves productivity by
Working in a group: Consider yourself
making the development process smooth.
working in a company where you are asked to
work on some live project. You can’t change
the main code as it is in production, and any becomes corrupted, and proper backups haven’t been
change may cause inconvenience to the user, kept? You lose absolutely everything.
also you are working in a team so you need to
collaborate with your team to and adapt their
changes. Version control helps you with the, Distributed Version Control Systems: Distributed
merging different requests to main repository version control systems contain multiple repositories.
without making any undesirable changes. You Each user has their own repository and working copy.
may test the functionalities without putting it Just committing your changes will not give others
live, and you don’t need to download and set access to your changes. This is because commit will
up each time, just pull the changes and do the reflect those changes in your local repository and you
changes, test it and merge it back. It may be need to push them in order to make them visible on
visualized as. the central repository. Similarly, When you update,
you do not get others’ changes unless you have first
Types of Version Control Systems:
pulled those changes into your repository.
Local Version Control Systems
A merge in Git is the process of integrating changes Fast-Forward merge vs Recursive merge:
from one branch into another. This is a common
practice in collaborative projects where multiple Fast Forward Recursive
developers work on different features or bug fixes in
separate branches. Merging helps combine their
efforts into the main branch, usually known No new commits on the New commits on the
as main or master. master master
Git provides several merge strategies, each suited for Linear History Commit 2 parents
different scenarios. The choice of strategy depends on
the complexity of changes and the desired outcome.
Here are the most commonly used merge strategies: Merge commit is
No merge commits
created
1. Fast Forward Merge:
Rebase and merge rewrites the commit history of the Apache Subversion is another open-source version
feature branch, placing it on top of the main branch control system that aims to be the best widely used
before merging. This results in a linear commit history VCS. It is a reliable option for valuable data. It is free
without merge commits. in terms of licensing costs but charges a reasonable
rate for inadequate features. It is a software
Use Case: Suitable for maintaining a clean and linear
versioning and revision control system that
project history, especially in projects with strict
developers use to manage versions of files for
commit guidelines.
websites.
git checkout feature-branch
Features:
git rebase main
git checkout main Security Management
git merge feature-branch
User Access Control
Types of Version Control Systems
Local Branching
Generally, VCS is categorized into two types –
Client-Server model of the repository
centralized and distributed. When choosing a VCS,
there’s always confusion about which one to The difference between the Concurrent Versions
choose, Centralized vs Distributed Version Control: System (CVS) and Subversion (SVN) will help you in
Which One Should We Choose? will guide you to knowing the difference between the two and gives
know the differences between the two. There are you an idea of choosing the best version control
numerous VCSs available in the market, based on system.
their features and popularity. While working on any
project, developers prefer to choose the one which 3. CVS (Concurrent Version Systems)
offers the best features. To help you with this kind of Concurrent Version Systems is an open-source, fully-
question Which Version Control Systems Should I featured tool that allows a developer to manage files
or repositories to switch between versions.
Developers can also record the history of source files, continuously improve the software by adding new
it keeps track of all modifications made in the source feature and for that we have to change the existing
code files. It allows developers to work on their own files and deploy them. Doing it manually every time
copy and later can be merged into a single file called may consume a lot of developer's time, so to make
master copy. It is the most reliable version control the process more simple and reliable developers
system. use CI/CD tools that are much more efficient and
make the whole process automated. As a software
Features:
Engineer or beginner in development, you should
Allows retrieval of the stored version know the best CI/CD tools.
Can share control of different versions of files As you go deep into software development, you will
ultimately need these tools to save time and release a
Does not allow commit errors to make more reliable and stable version of your software
Supports production of multiple versions of a application with proper automated testing and
file deploying processes. But before knowing the tools
let’s first under what exactly is CI and CD.
4. Mercurial
What is CI/CD?
Mercurial is a free, distributed version control system
to manage and track changes made across projects by CI and CD stand for continuous Integration and are
the software team. Popular organizations like Mozilla, continuous Deployment/Delivery which is used in the
World Web Consortium (W3), and Facebook process of building efficient software. These are the
use Mercurial as their version control system. The approaches that are used to integrate the code
best part about this version control system is that it changes into a shared repository (Continuous
efficiently handles any size of the project and offers an Integration) while automating the testing and
easy and intuitive interface. deployment process to the staging and production
environment (Continuous Delivery). These approaches
Features: are used to provide a more reliable and stable version
Fast and powerful of a software application by testing it before release
to end-users with the help of CI/CD Tools.
Easy for beginners as compared to Git
15 Best CI/CD Tools For Developers
Supports a multitude of workflows and easily
enhances its functionality with extensions Continuous Integration and Continuous Delivery are
not only necessary to build a great application but
Supports Windows, Unix, macOS, and Linux. also help the business in meeting its various
requirements, from automating tasks to receiving
5. AWS CodeCommit
quick feedback, so that developers can improve the
AWS CodeCommit is a version control system hosted application accordingly. They are both combined
by Amazon Web Services (AWS) to store and manage known as continuous software development. In this
files in the cloud. There’s no need to worry about process of developing efficient applications,
scaling its infrastructure, also storing anything from developers have created some CI/CS Tools that help
code to binaries is possible using AWS CodeCommit. It the software engineers test the software application
supports the standard functionality of Git to let it effectively. Here are some of the best CI/CD tools that
work seamlessly with existing Git-based tools. you should know
Features: 1. Jenkins
AWS provides the Amazon Elastic Container Service $ sudo apt-get remove docker docker-engine
( Amazon ECS ) it is an fully managed container service [Link] containerd runc
by which you can deploy, scale and manage the Step 2: Installing Docker Engine
docker containers. Amazon ECS is the most reliable
platform according to the performance and also it can The following command is used for
be integrated with the other AWS Service like load installation of docker engine:
balancing, service discovery, and container health $ sudo apt-get update
monitoring. To know more about Amazon Elastic
Container Service (Amazon ECS) . $ sudo apt-get install \
Difference Between Docker Containers and ca-certificates \
Virtual Machines curl \
gnupg \
The following are the differences between docker lsb-release
containers and Virtual Machines: $ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL
Docker Containers Virtual Machines [Link] |
sudo gpg --dearmor -o /etc/apt/keyrings/[Link]
$ echo \
Docker Containers Virtual Machines (VMs) run
"deb [arch=$(dpkg --print-architecture)
contain binaries, on Hypervisors, which
libraries, and allow multiple Virtual
signed-by=/etc/apt/keyrings/[Link]]
configuration files along Machines to run on a single [Link] \
with the application machine along with its own $(lsb_release -cs) stable" | sudo tee
itself. operating system. /etc/apt/[Link].d/[Link] > /dev/null
Check if docker is successfully installed in your Sample Example to Push an image to Docker Hub
system by trying to run a container with the
The following steps guides in pushing an image to the
following command:
Dockerhub:
$ sudo docker run hello-world
Step 1: Create an account on Docker Hub or use an
To more detailing on the installation of docker on existing one if you already have one.
ubuntu, refer this – Article
Step 2: Click on the “Create Repository” button, put
Sample Example: Containerizing Application Using the name of the file, and click on “Create”.
Docker
Step 3: Now will “tag our image” and “push it to the
The following steps guides in containerizing the Docker Hub repository” which we just created.
application using Docker:
Now, run the below command to list docker
Step 1: Create Dokcerfile and Python Application images:
$ sudo docker build -t python-test . 2. Now run the image, it will fetch the image from the
docker hub if it doesn’t exist on your local machine.
The ‘-t’ option allows to define the name of
your image. ‘python-test’ is the name we have $ docker run afrozchakure/python-test
chosen for the image.
Importance of Docker
Step 5: Run Docker Container
The following are the some of the insights that
Once the image is created, your code is ready discusses on the importance of docker:
to launch.
Efficiency and Speed : It facilitates with LXC (Linux Containers): Provides operating-
providing the streamlined development and system-level virtualization for running
deployment by packaging applications with multiple isolated Linux systems (containers)
dependencies into consistent containers. on a single host, offering a lightweight
alternative to Docker for certain use cases.
Resource Optimization : It helps in sharing
host system resources efficiently, allowing for containerd: An industry-standard core
higher application density and cost savings. container runtime developed by Docker, Inc.,
offering a minimal and stable platform for
Scalability and Portability : It is easily able to
building containerized applications, often
scale the applications and ensures seamless
used as a lower-level alternative to Docker for
movement across different environments.
more advanced container orchestration
Isolation and Security : it provides high systems like Kubernetes.
isolation, reducing conflicts and enhancing
Docker Security
security.
The following are the some of the insights on docker
Benefits of Docker
security:
The following are the some of the benefits of Docker:
Isolation : Docker containers provides the
Portability: Docker facilities with creation of strong isolation ensuring the applications and
lightweight portable containers that can be processing its running.
unable on any machine regardless of the
Immutable Infrastructure : It promotes the
underlying operating systems.
use of immutable infrastructure, where
Isolation: Docker through containers provides containers are build from the immutable
a high level of isolation with enabling the images that are version controlled.
applications to run independently of each
Resource Constraints: It allows you to define
other addressing the issues that one container
the resource constraints for containers such
doesn’t impact on other.
as CPU and memory limits.
Reproducibility: With, Docker developers can
Security Scanning: It provides the built-in
easily package their applications and their
security scanning tools that allows you to scan
dependencies into a reusable images. It
the container images for known
allows for consistent and repoduciable builds
vulnerabilities and malware before
across the development, testing and
deployment.
production environments.
Use Cases of Docker
DevOps Integration : It promotes the
collaboration and automation across the The following are the some of the use cases of
software development life cycle in handing Docker:
the increasing workloads.
Continuous Integration and Continuous
Alternatives of Docker Deployment (CI/CD) : It helps in streamlining
and automating the software delivery process
The following are the alternatives of Docker:
with ensuring faster and more reliable
Podman : Offers a Docker-compatible releases.
container engine with a focus on security and
Microservices Architecture: It facilitates the
compatibility, ideal for environments where
development, deployment, and management
Docker is not preferred or available.
of microservices with enabling independent
rkt: A lightweight container runtime scaling and maintenance.
developed by CoreOS, designed for simplicity,
Development Environment Consistency: It
security, and composability, offering an
will ensures with consistent development,
alternative to Docker’s container runtime.
testing, and production environments,
reducing “it works on my machine” issues.
Multi-Cloud and Hybrid Cloud
Feature Docker Kubernetes
Deployments: It helps in simplifying the
application deployment across various cloud
platforms, enhancing flexibility and reducing environments
vendor lock-in.
WORKDIR /directory-name
#Copy the current directory contents into the
11. USER container at current directory
COPY . .
It sets which user’s container will run as. This can be
useful if you have shared network directories involved #Install the mvn command for maven
that assume a fixed username or a fixed user number. RUN mvn install
Example: By using the above Dockerfile we can build an image
USER geeksforgeeks of Maven we are setting a Maven alpine image as a
USER 4000 base image with the help of FROM command and
with the help of WORKDIR setting the working
12. ARG directory for Maven and copy the required files and
A variable that can be provided at build time is folders to maven we are using the COPY command
defined by an ARG Instruction. Once it has been and RUN command can download the required
specified in the Dockerfile, you can specify it using the commands in the image we are downloading mvn
–build-arg switch when creating the image. The command.
Dockerfile supports multiple ARG instructions. The Note: # is used for comments in Dockerfile.
only instruction in the Dockerfile that can come
before the FROM instruction is ARG. Kubernetes – Introduction to Container
Orchestration
After the image is created, ARG values are not
accessible. An ARG variable value won’t be accessible In this article, we will look into Container
to a running container. Orchestration in Kubernetes. But first, let’s explore
the trends that gave rise to containers, the need for
Example container orchestration, and how that it has created
ARG image_name=latest the space for Kubernetes to rise to dominance and
FROM centos:$image_name growth.
docker build -t <image-name>:<tag> --build-arg The growth of technology into every aspect of our
image_name=centos8 . lives and days has created immense demand for
Best practices for writing Dockerfiles software, the companies, and organizations that sell
and deliver products based on software or just use
1. As a base image, use official images. And software in their businesses. This pressure has
whenever it is possible, use Alpine images as a spurred innovation and standardization. And the
base image. needs and stakes are so high it has fundamentally
changed how softwares are developed and deployed
2. Don’t copy unnecessary files and folders or
into production. But this evolution isn’t without
install/use unnecessary packages of software.
precedent. Could you imagine the world’s economy
relying on methods like using ships for the trade of and docker repositories define the dominant way of
goods?! There would be no way you’d get your new hosting versions of a container between developers
iPhone in time. Now we take it for granted that and between systems that need to use them, such as
shipping containers efficiently move between orchestration systems like kubernetes.
different modes of transportation different ship
owners and shipping companies and have
standardized ubiquitous and available anywhere in
the world almost, always no matter what it’s in.
Modern software is becoming quite similar. As
software systems become more complicated this
complication has driven software to be divided into
smaller pieces such as microservices. Whether they’re
called microservices or not these smaller pieces of
software each need to be packaged, built, deployed,
and accessed by other pieces of software around
them to function as a total system.
Example of Internal Service: In Kubernetes, we just connect Config Map to the Pod
so that the Pod actually gets the data that Config Map
[Link]
contains. Now if we want to change the name of the
Example of External Service: service, or the endpoint of the service, we just have to
edit the config map and that's it. We don't have to
[Link] build a new image and go through that whole cycle
however this URL of the external service is not very again.
practical, it is good for test purposes but not for the 6. Secret
end product so usually you will want your URL to look
like this if you want to talk to your application with a Secret is just like config map but the difference is that
secure protocol and a domain name - it's used to store secret data credentials and it stores
this data not a plain text format but in base64
[Link] encoded format.
And for that we use Ingress. Role of Secret
5. Ingress Role of Secret like we just discussed is similar to that
The official definition of Ingress says "Ingress is of a Config map. Secret is used to store the data and
an API object that manages external access to the credentials that we would not want to share with
services in a cluster". others.
Role of Ingress
The role of Ingress is that instead of Service, the Database Username and Password can also be part of
request goes first to Ingress and it does the the external configuration. Username and Password
forwarding then to the Service. may also change in the application deployment
process but putting a password or other credentials in
a Config Map in plain text format would be insecure.
6. Config Map For this purpose Kubernetes has the component
called Secret. The passwords, certificates, etc that you
Config Map is the external configuration to your don't want other people to have access to would go in
application. Config Map usually contains configuration the Secret. Just like Config Map you can just connect it
data like URLs of database or URLs of some other to your Pod so that the Pod can actually see those
services that we are using. data and read from the Secret.
Role of Config Map 7. Volumes
Pods communicate with each other using a Service. A Volume in Kubernetes is a data storing feature with
Our application will have a database end point, For the help of which we can store data that is persistent
example, mongo-db-service will have a database end and can be accessed by containers in a Kubernetes
point that it uses to communicate with the database. pod.
Now the problem is where should we configure?
Usually we would keep this database URL or Role of Volumes
endpoints inside of the built image of the application. In our current diagram, we have the database Pod
And there is an issue with that - For example, if the that our application uses and it has some data or it
endpoint of the Service or Service name in this case generates some data. The issue with this Pod is that if
changed to mongo-db. We will have to adjust that the database container or the Pod gets restarted, the
URL in the application and we would have to rebuild data would be gone. We would want your database
the application with a new version, then push it to the data or log data to be persisted in the long-term and
repository and then pull that new image in our pod
that is why we have the Kubernetes component convenient to interact with the Pods, replicate them
called Volumes. and do some other configuration. Now if one of the
replicas of our replication Pod would die, the Service
How Volumes do this is that it basically attaches a
will forward the requests to another one so our
physical storage on a hard drive to your Pod. That
application would still be accessible for the user.
storage could be either on a local machine (meaning
on the same server node where the Pod is running) or 9. StatefulSet
it could be on a remote storage (meaning outside of
StatefulSets are the Kubernetes component that
the Kubernetes cluster). Now when the database Pod
manages the replication and lifecycle of the Pods in
or the Container gets restarted, all the data will be
the Kubernetes Cluster but specifically for Stateful
there persisted.
applications.
8. Deployment
Role of StatefulSet
Deployment are the Kubernetes component that
Deployment solved our problems with the application
manages the replication and lifecycle of the Pods in
Pod but what about the database Pod? Because if the
the Kubernetes Cluster.
database Pod dies, our application also would not be
In our current example, what happens if our accessible so we need database replicas as well
application Pod dies, crashes or I have to restart the however we can't replicate database using
Pod because I built a new container image? What a deployment. The reason for that is because
happens is that we will have a downtime where the database has a state (which is its data) meaning that if
users will not be able to reach our application. This is we have closed a set of replicas of the database, they
a terrible thing if it happens in production. would all need to access the same shared data
storage and there we would need some kind of
Role of Deployment
mechanism that manages which Pods are currently
The role of StatefulSets and Deployment is exactly writing to that storage or which Pods are reading from
this. When using distributed systems and containers, that storage. We will have to do this in order to avoid
instead of relying on just one application Pod and one data inconsistencies.
database Pod etc. We can replicate everything on
This mechanism in addition to replicating feature is
multiple servers, so we would have another node
offered the Kubernetes component called StatefulSet.
where a replica or clone of our application would run
StatefulSet is meant specifically for applications like
which will also be connected to the Service. Previously
databases. StatefulSet just like deployment would
we discussed that the service is like an persistent
take care of replicating the pods and scaling them up
static IP address with a DNS name so that you don't
or scaling them down but making sure that database
have to constantly adjust the end point when pod
reads and writes are synchronized so that no database
dies. The Service is also a load balancer which means
inconsistencies are offered. however deploying
that the service will actually catch the request and
database applications using StatefulSets in Kubernetes
forward it to whichever Pod is the least busy.
cluster can be somewhat tedious that's why it is also a
In order to create the second replica of the my common practice to host database applications
application pod we will not create a second Pod outside of the Kubernetes cluster and just have the
rather we will define a blueprint in our application deployments or stateless applications that replicate
Pod and specify how many replicas of that pod we and scale with no problem inside of the Kubernetes
want to run. That component or that blueprint in Cluster and then communicate with the external
Kubernetes is called Deployment. Actually we don't database.
even work with Pods or create Pods, we rather create
How to Use AWS ECS to Deploy and Manage
creating Deployments and StatefulSets and there we
Containerized Applications?
can specify how many replicas we want and we can
scale up or scale down number of replicas of Pods. Last Updated : 25 Oct, 2023
Yes, we can run ecs tasks as stand alone and as well Features of IaC
as part of ecs service.
Automation: IAC automates the provisioning
6. Can We Integrate With Our Services Like Cloud and configuration of infrastructure, reducing
Watch, Load Balancers Etc ? manual errors and saving time.
Yes, ecs can be well integrated with other services Repeatability: IAC scripts can be used
including cloud watch and load balancers. repeatedly, making it easy to recreate the
same infrastructure in multiple environments.
Improved Security: IAC helps ensure that Increased Collaboration: IAC enables multiple
infrastructure is configured consistently and people to work on infrastructure projects,
securely, reducing the risk of security making it easier to share knowledge and
vulnerabilities. collaborate.
Networking: IAC can be used to automate the Initial setup time: Implementing IAC requires
deployment and management of networks, time and effort, as it requires writing scripts,
including creating and managing subnets, testing them, and integrating them into the
security groups, and firewalls. existing environment.
Web application deployment: IAC can be Complexity: IAC can introduce complexity, as
used to automate the deployment and it requires multiple components to work
management of web applications, including together and can be difficult to debug if
specifying the web server, application server, something goes wrong.
and load balancer.
Dependency management: IAC can create
Database deployment: IAC can be used to dependencies between components, making
automate the deployment and management it more difficult to make changes or update
of databases, including specifying the components individually.
database engine, creating tables, and
Fragility: IAC scripts can be fragile, as a small
configuring users.
mistake in the code can have a significant
Big data: IAC can be used to automate the impact on the infrastructure.
deployment and management of big data
Use Cases of IaC
infrastructure, including setting up clusters
and configuring data processing frameworks Provisioning Virtual Machines (VMs): Using
such as Apache Hadoop or Apache Spark. IAC, you can write code to provision VMs in a
cloud computing environment, and specify
Advantages of IaC
the number of VMs, the operating system, Multi-Cloud Management: You can manage
and the required software. the infrastructure of different cloud platform
at a time which will helps you to maintain the
Deploying a Network: You can use IAC to
multi-cloud or hybrid cloud environments.
deploy a network, specify the network
topology, create subnets, and configure Infrastructure Versioning and
security groups. Collaboration: You can store the scripts which
have been written to provision the
Setting up a Database: You can write code to
infrastructure in the version control system
set up a database, specify the database
like git form where other teams can
engine, configure users, and define the
collaborate on infrastructure changes, track
schema.
revisions, and roll back to previous states if
Deploying a Web Application: You can use needed.
IAC to deploy a web application, specify the
Automation and Continuous
web server, configure the application server,
Integration/Continuous Deployment
and set up load balancing.
(CI/CD): You can also integrate the terraform
Managing DNS Records: You can use IAC to into you CI/CD pipelines where ever the build
manage Domain Name System (DNS) records, is triggered if there is any changes the
automate the creation and deletion of infrastructure will upgrades automatically.
records, and ensure consistency across
Working of Terraform
multiple environments.
With Terraform, users can define infrastructure
Terraform is an open-source infrastructure as code
resources using a simple, declarative configuration
(IaC) software tool which can be used to provision the
language. These resources can include virtual
infrastructure of a cloud platform. The HCL scripts
machines, networking components, storage
which have been used to provision infrastructure can
resources, and more. Once the configuration is
be human-readable configuration files that can be
defined, Terraform can be used to create, modify, and
versioned, reused, and shared. You can provision wide
destroy these resources in a repeatable and
range of resources in the cloud by using terraform like
predictable [Link] know more aboput terraform
compute, storage, networking, and application
work flow.
services, across a variety of cloud providers and on-
premises environments. One of the key benefits of Terraform is its ability to
support multiple cloud providers, as well as on-
Infrastructure as a Code (IaC)
premises and open-source tools. This means that
Infrastructure as Code (IaC) is a method of managing users can define infrastructure resources using a
and provisioning IT infrastructure using code, rather single configuration and use Terraform to manage
than manual configuration. It allows teams to resources across different environments.
automate the setup and management of their
Overall, Terraform is a powerful and flexible tool that
infrastructure, making it more efficient and
enables users to define and manage infrastructure
consistent. This is particularly useful in the DevOps
resources in a reusable and automated way. It is
environment, where teams are constantly updating
widely used in a variety of industries and scenarios,
and deploying software. To know more
including cloud infrastructure, data centers, and
about Infrastructure as a Code (IaC).
hybrid environments.
Use Cases of Terraform
$ terraform refresh
1. Terraform CLI
2. Terraform validate
Terraform is an open-source tool that is packaged into
The validate command performs precisely what its a single executable binary, which you can download
name implies. It ensures that the code is internally and run directly from the command line. This tool
coherent and examines it for syntax mistakes. Only helps you automate the creation and management of
the configuration files (*.tf) in the active working infrastructure. To see a list of available commands in
directory are examined. You must provide the -a Terraform, you can run:
recursive flag if you want to validate files inside of
folders (for example, if you have a module/ directory). terraform --help
$ terraform validate This command will display all the available commands,
with the most commonly used ones listed first. The
3. Terraform apply primary Terraform commands include:
Terraform apply command applies the changes init: Prepares your directory to run other
defined in the configuration to your infrastructure. It Terraform commands.
creates or updates the resources according to the
configuration, and it also prompts you to confirm the validate: Checks if the configuration is valid.
changes before applying them.
plan: Shows what changes will be made to
$ terraform apply your infrastructure.
Terraform destroy command will destroy all the In addition to these, there are other commands for
resources created by Terraform in the current working various tasks like formatting code (fmt), managing
directory. It is a useful command for tearing down state (state), and more.
your infrastructure when you no longer need it.
2. Terraform Language
$ terraform destroy
Terraform uses HashiCorp Configuration Language
5. Terraform import (HCL) to define infrastructure. HCL is designed to be
both easy to read by humans and understandable by
Imports an existing resource into the Terraform state,
machines, making it a great fit for DevOps tools.
allowing it to be managed by Terraform.
Infrastructure elements managed by Terraform are and shared on the Terraform Registry, enabling users
called resources. These can include virtual machines, to reuse and extend the infrastructure code of others.
S3 buckets, VPCs, and databases. Each resource is
5. Terraform Provisioners
defined in a block, like this example for creating an
AWS VPC: Provisioners are special tools in Terraform that let you
execute commands on your infrastructure after it’s
resource "aws_vpc" "default_vpc" {
been created. For example, you can use provisioners
cidr_block = "[Link]/16"
to copy files to a virtual machine or run scripts for
tags = {
further configuration.
Name = "example_vpc"
} However, provisioners should be used with caution
} because they can complicate your setup and may
require higher-level permissions. It’s best to only use
3. Terraform Provider
them when no other Terraform constructs (like
A software element known as a Terraform provider resources or modules) can achieve the same result.
enables Terraform to communicate with a particular
6. Terraform State
infrastructure platform. The resource kinds and data
sources that Terraform can handle for that platform Terraform keeps track of your infrastructure and its
must be implemented by [Link] platforms, current state in a file called [Link]. This file
data centres, network devices, databases, and other contains information about your infrastructure
resources inside the target infrastructure or service resources, which helps Terraform determine what
can all be defined, configured, and managed by changes to make during future operations.
Terraform providers.
The state can be stored locally on your machine, but
4. Terraform Modules in collaborative settings, it’s usually better to store it
remotely to ensure everyone on the team is working
In Terraform, a module is a container for a set of
with the same state information.
related resources that are used together to perform a
specific task. Modules allow users to organize and Advantages of Terraform
reuse their infrastructure code, making it easier to
manage complex infrastructure deployments. Declarative Configuration: Terraform uses a
declarative configuration language, which
Modules are defined using the ‘ module ‘ block in means that users define the desired state of
Terraform configuration. A module block takes the their infrastructure resources, rather than the
following arguments: specific steps required to achieve that state.
This makes it easier to understand and
source: The source location of the module.
manage complex infrastructure deployments.
This can be a local path or a URL.
Support for Multiple Cloud
name: The name of the module. This is used
Providers: Terraform supports multiple cloud
to reference the module in other parts of the
providers, as well as on-premises and open-
configuration.
source tools, which means that users can
version: The version of the module to use. define and manage their infrastructure
This is optional and can be used to specify a resources using a single configuration.
specific version of the module.
Reusable Infrastructure Code: Terraform
Inside a module block, users can define the resources allows users to define their infrastructure
that make up the module, as well as any input and resources in a reusable and modular way,
output variables that the module exposes. Input using features such as modules and variables.
variables allow users to pass values into the module This makes it easier to manage and maintain
when it is called, and output variables allow the complex infrastructure deployments.
module to return values to the calling configuration.
Collaboration and Version Control: Terraform
Modules can be nested, allowing users to create
configuration files can be stored in version
complex infrastructure architectures using a
control systems such as Git, which makes it
hierarchical structure. Modules can also be published
easier for teams to collaborate and track 1. Terraform vs AWS CloudFormation
changes to their infrastructure.
AWS
Efficient Resource Management: Terraform
Feature Terraform CloudFormation
has features such as resource dependencies
and provisioners that enable users to manage
their infrastructure resources efficiently, Works with
minimizing duplication and ensuring that multiple cloud
resources are created and destroyed in the Limited to AWS
providers
correct order. with minimal
(AWS, Azure,
third-party
Disadvantages of Terraform GCP, etc.) and
support.
Provider on-prem
Complexity: Terraform can be complex to Support services.
learn and use, especially for users who are
new to infrastructure automation. It has a
large number of features and can be difficult Uses
to understand the full scope of its capabilities. HashiCorp
State Management: Terraform uses a state Configuration Uses YAML or
file to track the resources it manages, which Language JSON, tailored
can cause issues if the state file becomes out (HCL), which is for AWS
of sync with the actual infrastructure. This can provider- services.
happen if the infrastructure is modified neutral and
outside of Terraform or if the state file is lost Language declarative.
or corrupted.
Maintains a
Doesn’t require
Uses HCL for State state file for
Uses YAML for state files.
infrastructure Management consistency.
defining tasks.
Language definitions.
Useful for multi- Amazon Web Services (AWS) is the service offered by
cloud the AWS cloud it is mainly used to provision the
Excellent multi-
configurations service in the AWS like EC2, S3,Autoscaling, load
cloud
but limited to balancing and so on you can provision all the service
capabilities.
Cloud system-level automation with the Infrastructure as a code (IAC),
Support tasks. instead of managing all of them manually you can
manage with the help of AWS Cloudformation.
3. Terraform vs Chef
Infrastructure Automating
creation and system
Primary Use updates. configurations.
Features Of AWS Cloudformation
1. No up-front investment
Uses Ruby-
Uses HCL,
based DSL, 2. Lowering operating cost
which is easy to
which is more
learn. 3. Highly scalable
Language complex.
4. Easy access
Conditions: Conditions are used to define if CloudFormation comes with several built-in functions
certain resources are created or when the (like Fn::Sub, Fn::Join), and these functions are aimed
resource’s properties are assigned to a value at making dynamic configuration easier so that as the
when the stack is created. resources are being deployed, their properties can be
adjusted and modified.
Transform: Transform helps in reusing the
template components by building a simple [Link]
declarative language for AWS
These offer an opportunity for user interaction during
CloudFormation.
the deployment of the stack thus making it easier to
Resources: In this, you can specify the create templates that are flexible and reusable. For
properties of AWS resources (AWS EC2 instance, given the instance types, VPC ids or
instance, S3 bucket, AWS lambda ) you want environment variables can be indicated as
in your stack. parameters.
[Link] Sets
Deploying a CloudFormation template can be done early, ensuring that only compliant resources
through multiple methods, each catering to different are allowed into your cloud environment.
preferences and workflows
2. Personalized Checks: You can create your
[Link] Management Console own checks to ensure resources meet specific
standards before deployment, giving you
The AWS Management Console offers a user-friendly
flexibility to enforce the rules that suit your
way to deploy templates. Simply log in, navigate to
organization’s needs.
CloudFormation, and select “Create Stack.” You can
then upload your template (in JSON or YAML format), 3. Managing Resource Lifecycles: Easily track
configure parameters, tags, and permissions, and and manage resources from start to finish,
finalize by clicking “Create Stack.” This method is ideal ensuring they follow your rules and meet
for those who prefer a visual, straightforward compliance throughout their entire existence.
interface.
4. Cost Optimization: Helps control costs by
[Link] Designer enforcing guidelines that prevent unnecessary
spending on resources and Ensures smart
For a more graphical approach, CloudFormation
spending by setting rules that limit resource
Designer allows users to visually build or modify
usage and prevent overspending.
templates using a drag-and-drop interface within the
AWS Console. After creating or adjusting your 5. Enhanced Security: Boosts safety by applying
template, deployment is just a click away by selecting strict security measures to prevent
“Create Stack.” This method suits users who enjoy unauthorized access and potential risks
visual tools for infrastructure design. Strengthens protection
[Link] CLI (Command Line Interface) How to Create AWS CloudFormation Template
After ensuring the AWS CLI is installed and configured, Two ways To Create CloudFormation template
you can deploy your template by running a simple
[Link] Pre-Built Template
command. This method is particularly useful for
developers who want to integrate deployments into When creating a CloudFormation template, you can
CI/CD pipelines or automate infrastructure tasks. choose from two options within this method:
What Are AWS CloudFormation Hooks? Choose an Existing Template : Select a
previously created template and modify it
AWS CloudFormation Hooks is a feature that you can
according to your current needs.
employ to retain the compliance of your
CloudFormation resources in regards to security Use a Sample Template : This article follows
operational and cost optimization compliance within this approach. AWS offers several sample
your organization. CloudFormation Hooks allow you templates that you can use as a starting point.
to implement code that proactively checks the You can select a sample template from the
configuration of your AWS resources before they are available options in AWS, then customize it as
provisioned. If any resources are found to be non- needed to deploy your desired infrastructure.
compliant CloudFormation can either block the As covered in the steps below, to customize
operation to prevent provisioning or issue a warning and deploy the desired infrastructure.
while allowing the process to continue
[Link] Building Your Own From Scratch
What Are the Benefits of Using CloudFormation
Hooks? Use Application Composer to create your
CloudFormation template visually. This tool offers a
1. Automatic Compliance drag-and-drop interface to design and configure
Checking: CloudFormation Hooks infrastructure, generating the template automatically.
automatically check your resources to ensure Ideal for those who prefer a more hands-on approach
they meet your organization’s rules and with visual assistance.
standards before they are deployed. This
helps prevent issues by catching problems Steps To Provision EC2-instance and LAMP
package Using AWS CloudFormation
Using AWS cloud FormationCreate, we will be creating
a template using which instance will be launched and
the LAMP package will be installed on top of it
automatically. To create AWS free tier account you
can refer to Amazon Web Services (AWS) – Free Tier Step 5: This is the code written in JSON format which
Account Set up. contains all the specifications and dependencies
about the infrastructure to be created.
Step 1: Go to the Cloudformation dashboard on the
AWS management console. Click on Create the stack.
Step 10: Choose the instance type. Select any AWS CloudFormation Terraform
available key pair which will be used in making an SSH
connection with the instance. Click on Next.
Supports
multiple cloud
providers,
AWS-specific, designed for AWS
making it
services.
versatile for
multi-cloud
environments.
Implement Log Rotation: Regularly archive Data Retention: The services should retain
and remove old log files to save disk space data for a sufficient amount of time to meet
and improve performance. auditing and compliance requirements.
Use Log Levels: Use log levels such as In addition, implementing Monitoring and Logging
“debug”, “info”, “warning”, and “error” to services can be complex and time-consuming. It is
categorize log messages and make it easier to important to have a clear plan and dedicated
filter and analyze the data. resources for the implementation and maintenance of
these services. This can include a team that is
Monitor Critical Metrics: Monitor key metrics
responsible for setting up the monitoring and logging
such as system resource usage, network
infrastructure, configuring the services, and analyzing
traffic, and error rates to quickly identify and
the data.
troubleshoot issues.
Conclusion
Implement Alerting: Set up alerts to notify
you when certain conditions are met, such as In conclusion, monitoring and logging services are
a high error rate or low disk space. essential for any organization that wants to ensure
the reliability, performance, and security of its
Use a Monitoring Solution: Use a monitoring
systems. These services allow organizations to detect
tool such as Prometheus, Grafana, or New
and resolve issues quickly, and provide a historical
Relic to collect and analyze data.
record of what has happened on a system. While
Use a Log Aggregation Tool: Use a log implementing monitoring and logging services can be
aggregation tool such as ELK (Elasticsearch, complex, the benefits of having these services in a
Logstash, Kibana) or Splunk to search, place far outweigh the cos
analyze, and visualize log data.
What is DevSecOps?
Implement Security: Ensure that logs and
DevSecOps stands for Development, Security, and
monitoring data are protected from
Operations. It is a software development approach
unauthorized access by implementing proper
that emphasises on integration of security and
security measures such as encryption and
operations in the software development process. It
authentication.
involves the collaboration of the developing team,
Regularly Review and Improve: Regularly testing team, security professionals, and operations
review your logging and monitoring practices, team. The goal of DevSecOps is to build and maintain
and make improvements as necessary to secure software by creating and adapting a
ensure that you are effectively monitoring continuous environment of security into the
your systems and applications. software development process.
When implementing monitoring and logging services, DevSecOps helps organizations quickly identify and
it is important to consider the following solve potential security vulnerabilities for the
development team that relies on an agile and rapid
Scalability: The services should be able to software development lifecycle model. It
handle a large amount of data, and scale up accelerates modern software prototyping and agile
or down as needed. framework development while addressing security
Integration: The services should integrate issues during the development phase only, being an
with existing systems and tools. effective methodology that increases software quality
and ensures fast delivery.