How to Install Helm using Ansible Playbook?

Managing various infrastructure and applications under different conditions in the present dynamic IT landscape can challenge. Automation tools like Ansible assist with smoothing out these undertakings by providing a basic yet amazing method to automate configuration management, application deployment, and orchestration. One essential part of the Kubernetes environment is Helm, a package manager for Kubernetes that streamlines the deployment and the management of applications and services. By merging the abilities of Ansible and Helm, associations can achieve considerably more noteworthy efficiency, consistency, and reliability quality while working with their Kubernetes environments. In this article, we’ll show how to use Ansible, a well-known automation tool, to install Helm on servers or Kubernetes clusters.

Here is a key guide with terminology, processes, and guidance that will not only assist you to concretely comprehend but also perform the Helm installation via the Ansible playbook with relative certainty. Whether you are a meticulously organized DevOps engineer or possibly just looking to get all started with automation, the information and skills it will offer you will enable you to handle the installation of Helm to perfection in your situation.

Primary Terminologies

  • Helm: Helm is a package manager for Kubernetes that works on the deployment and management of Kubernetes clusters. Helm utilizes graphs, which are charts of pre-designed Kubernetes resources, to define, introduce, and redesign applications.
  • Ansible: Ansible is an open-source automation tool utilized for configuration management, application deployment, and orchestration. It permits you to define infrastructure as code utilizing playbooks, which are YAML records containing a set of tasks to be executed on remote hosts.
  • Playbook: An Ansible playbook is a YAML file that contains a set of instructions, called tasks, to be executed on remote hosts. Playbooks define the ideal condition of the infrastructure and determine the assignments expected to accomplish that state.
  • Task: A task is an activity performed by Ansible on a remote host, like installing packages, copying documents, or beginning services, Tasks are defined inside playbooks and are executed consecutively on each target host.
  • Inventory: An inventory is a file that lists the hosts or nodes on which Ansible tasks will be executed. It defines the target hosts and their association subtleties, for example, IP addresses, hostnames, SSH keys, and groupings.
  • Role: An Ansible role is a reusable set of tasks, controllers, variables, and templates that can be remembered for playbooks to carry out specific roles, Roles help arrange and modularize playbooks, making them simpler to keep up with and reuse across various projects. Roles encapsulate normal arrangements, examples, and best practices for managing infrastructure.

What is Helm?

Helm is a package manager for Kubernetes, working with the deployment, management, and scaling of uses and services on Kubernetes clusters. It smoothes out the most common way of defining, installing, and upgrading applications using Helm charts.

A Helm chart is an collection of Kubernetes manifests packaged together, including deployment configurations, service definitions, and different resources important to run an application on Kubernetes, outlines give a normalized method for define the design and dependencies of an application, making it more straightforward to share and reuse configurations across various conditions.

With Helm, users can easily install and manage complex applications with a single command, empowering fast turn of development and deployment cycles. Moreover, Helm supports versioning, allowing users to manage various arrivals of an application and rollback to past variants if necessary.

Step-By-Step Process to Install Helm using Ansible Playbook

Step 1: Launch EC2 Instances

  • Sign into AWS Console with credentials
  • Now launch two instances one for master and another for slave node

  • Connect with terminal like git bash, putty

Step 2: Install Ansible

 sudo amazon-linux-extras install ansible2

Step 3: Create a playbook

  • Now create a playbook with .yml extension
sudo vi <filename.yml>
  • Here is the playbook script to install helm
- name: Install Helm
hosts: local
become: yes
tasks:
- name: Install curl (if not already installed)
package:
name: curl
state: present

- name: Download Helm installation script
get_url:
url: https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
dest: /tmp/get_helm.sh
mode: '0755'

- name: Run Helm installation script
command: /tmp/get_helm.sh
args:
creates: /usr/local/bin/helm
register: helm_install_result
changed_when: false

- name: Add /usr/local/bin to PATH
lineinfile:
path: ~/.bashrc
line: 'export PATH=$PATH:/usr/local/bin'
when: helm_install_result.rc == 0

Here is the script explanation

Name and Host: The playbook is named “Install Helm” and is defined to run on the local machine (hosts: local).

Tasks:

  • Install curl: This task ensures that the curl package is introduced on the framework. It utilizes the bundle module with the state: present boundary to install curl in the event that it’s not already installed.
  • Download Helm installation script: This task downloads the Helm installation script from the Helm GitHub repository (https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3) and saves it to/tmp/get_helm.sh. It sets the method of the downloaded script to executable (mode: ‘0755’).
  • Run Helm installation script: This task executes the Helm installation script (/tmp/get_helm.sh) with the command module. The args segment ensures that the task only runs if/usr/local/bin/helm doesn’t as of now exist (creates:/usr/local/bin/helm). The consequence of this task is put away in the variable helm_install_result.
  • Add/usr/local/bin to PATH: This task adds/usr/local/bin to the PATH environment variable in the user’s ~/.bashrc file. It utilizes the lineinfile module to add the product explanation to the ~/.bashrc file provided that Helm was effectively installed (when: helm_install_result.rc == 0).

Step 4: Setting up Host Permission for slave node

  • Now move to ansible directory path. In that ansible directory there is a file for HOST.
  • Below path is default path for host file in ansible
cd /etc/ansible/ 

  • Now open that Host file by using following command.
  • Inside this file provide target group or host server details like IP Address
sudo vi host 

  • Ensure that our instance keypair’s was downloaded in local machine that is our master node.
  • This command provide SSH access to your target group
 scp -i keyapir.pem keypair.pem ec2-user@public-IP-address:/home/ec2-user(path to download)
  • After that change permissions to that key pairs’ file, we are providing only read permissions
sudo chmod 400 <keypair.pem>

  • To connection between master and slave was connected are not by using following command
ansible ping -m all

Step 5: Run Playbook

Now run the ansible playbook by using following command

ansible-playbook <filename.yml>

Step 6: Verify

Go to AWS EC2 dashboard and connect slave node to terminal and check helm version by using following command

helm version

Conclusion

Helm plays a significant role in improving on the management of utilizations and services on Kubernetes clusters. By giving a robust package manager and a normalized method for defining application designs through Helm charts, Helm smoothes out the deployment, scaling, and updating processes.

With Helm, users can use pre-arranged charts from the Helm hub or make custom charts custom-made to their particular necessities, this empowers fast turn of development and deployment cycles, as well as advances consistency and unwavering quality across various conditions.

Generally, Helm altogether works on the efficiency and productivity of DevOps teams via automating repetitive tasks, upholding best practices, and cultivating cooperation through the sharing and reuse of outlines. As Kubernetes reception keeps on developing, Helm stays a basic apparatus for managing complex applications and services in Kubernetes conditions.

Install Helm using Ansible Playbook – FAQs

Is Helm just utilized for deploying applications on Kubernetes?

Some time Helm is essentially intended for managing applications on Kubernetes, it can likewise be utilized to manage different sorts of resources, for example, Kubernetes configurations, Helm modules, and repositories

How in all actuality does Helm differ from other package managers like apt or yum?

Helm is explicitly custom fitted for Kubernetes and gives more significant level deliberations to managing applications and administrations on Kubernetes groups. It improves on the packaging, deployment, and the executives of uses in a Kubernetes-local way, though apt and yum are package manager for Linux circulations and manage programming packages at the operating system level.

Could I at any point utilize Helm to manage Kubernetes resources other than applications?

Yes, Helm charts can be utilized to define and manage different Kubernetes resources, including deployment, services, ingresses, configmaps, secrets, and then some. Helm gives adaptability in defining resources designs, making it reasonable for dealing with an extensive variety of Kubernetes resources.

How would I make my own Helm outline?

You can make a Helm charts utilizing the Helm CLI device or by physically composing the necessary files. Helm gives commands to platform another chart, including layouts for normal Kubernetes resources. You can then alter the chart to define the design, conditions, and arrangements of your application.

Can Helm be integrated with CI/CD pipelines?

Yes, Helm can be incorporated into CI/CD pipelines to automate the deployment of uses on Kubernetes clusters. Helm outlines can be form controlled close by application code, and Helm commands can be executed as a feature of CI/CD work processes to package, deploy, and manage applications reliably across various conditions.



Contact Us