[Ansible Galaxy] Use Ansible community.kubernetes.helm to manages Kubernetes (K8S) packages with the Helm package manager

community.kubernetes.helm

community.kubernetes.helm is an Ansible Galaxy to install, upgrade, delete packages with the Helm to manages Kubernetes packages with the Helm package manager

Ansible is Simple IT Automation - https://www.ansible.com/ can configure systems, deploy software, and orchestrate more advanced IT tasks such as continuous deployments or zero downtime rolling updates.

Ansible’s main goals are simplicity and ease-of-use. It also has a strong focus on security and reliability, featuring a minimum of moving parts, usage of OpenSSH for transport (with other transports and pull modes as alternatives), and a language that is designed around auditability by humans–even those not familiar with the program.

Ansible is a universal language, unraveling the mystery of how work gets done. Turn tough tasks into repeatable playbooks.

This article is about how to use community.kubernetes.helm to manage releases with the Helm package manager.

Prerequisites

  • Kubernetes (K8S)
    Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.

  • Helm
    Helm is the best way to find, share, and use software built for Kubernetes.

Installation

Install Ansible

1
2
3
4
# Mac OS X
$ brew install ansible

$ ansible --version

Install community.kubernetes

This plugin is part of the community.kubernetes collection.

To install it use:

1
$ ansible-galaxy collection install community.kubernetes

Examples

To use it in a playbook, specify: community.kubernetes.helm. For example use ommunity.kubernetes.helm to install nfs-server-provisioner helm chart.

See the directory structure.

1
2
3
4
5
$ tree .
.
└── playbooks
├── helm.yml
└── values.yaml

Edit the playbook file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# playbooks/helm.yml

---
- name: Install Kubernetes (K8S) packages by community.kubernetes.helm.
# become: yes
hosts: localhost

tasks:
- name: Install python package.
pip:
name:
# PyYAML · PyPI
# https://pypi.org/project/PyYAML/
# or pip install PyYAML
- PyYAML

# community.kubernetes.helm - Manages Kubernetes packages with the Helm package manager — Ansible Documentation
# https://docs.ansible.com/ansible/latest/collections/community/kubernetes/helm_module.html
# helm repo add jetstack https://charts.jetstack.io && helm repo update
- name: Add jetstack chart repo
community.kubernetes.helm_repository:
name: jetstack
repo_url: "https://charts.jetstack.io"

# helm install cert-manager jetstack/cert-manager --namespace cert-manager --version 1.0.4 -f values.yaml
- name: Deploy cert-manager chart using values files on target
community.kubernetes.helm:
binary_path: /usr/local/bin/helm
name: cert-manager
chart_ref: jetstack/cert-manager
chart_version: 1.0.4
# kubectl create namespace cert-manager
create_namespace: true
release_namespace: cert-manager
values: "{{ lookup('file', 'values.yaml') | from_yaml }}"
1
$ ansible-playbook -i hosts playbooks/helm.yml

See Helm release about cert-manager.

1
2
3
$ helm list --namespace cert-manager
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
cert-manager cert-manager 1 2020-09-12 11:24:36.704126 +0800 +0800 deployed cert-manager-v1.0.2 v1.0.2

See pods about cert-manager.

1
2
3
4
5
$ kubectl get pods -n cert-manager
NAME READY STATUS RESTARTS AGE
cert-manager-57b65b7fc-dczgc 1/1 Running 5 13d
cert-manager-cainjector-5f988f74c6-9ll6k 1/1 Running 5 13d
cert-manager-webhook-7cf554f879-ktkmg 1/1 Running 3 13d

More examples

Visist community.kubernetes.helm - Manages Kubernetes packages with the Helm package manager — Ansible Documentation: https://docs.ansible.com/ansible/latest/collections/community/kubernetes/helm_module.html to see more examples.

References

[1] community.kubernetes.helm - Manages Kubernetes packages with the Helm package manager — Ansible Documentation: https://docs.ansible.com/ansible/latest/collections/community/kubernetes/helm_module.html

[2] Ansible is Simple IT Automation - https://www.ansible.com/

[3] Installing Ansible — Ansible Documentation - https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html