Ansible Molecule with Kind - Kubernetes Automation Testing with Docker
Ansible Molecule with Kind - Kubernetes Automation Testing with Docker
May 26, 2022
Ansible Molecule with KIND (Kubernetes IN Docker)
- Ansible Molecule is a tool that helps you test environment setup by isolating Ansible roles with virtualization.
- KIND is a tool that runs a Kubernetes cluster as docker containers. Used for deploying resources on a Kubernetes cluster and checking them, or verifying application behavior. (ex, Helm Chart)
Prerequisites
- Install Docker Engine
- Install KIND
- Install Python libraries
pip install molecule[docker,lint] molecule-docker!=0.3.4 openshift
- Install Ansible collections
ansible-galaxy collection install community.kubernetes community.docker
Writing and Running the Test Scenario
- Create the Ansible role
| |
- Initialize the Molecule default scenario
| |
- Create the KIND Config manifest file
| |
- Edit the Molecule default scenario configuration
| |
- Edit the Molecule default scenario create playbook
| |
- Edit the Molecule default scenario destroy playbook
| |
- Edit the Molecule default scenario converge playbook
| |
- Edit the Molecule default scenario verify playbook
| |
- Test the Molecule default scenario
| |
Notes
- KIND is built from base/node images
- The base image has the programs Kubernetes needs to run, such as ubuntu, systemd, and containers
- The node image is built on the base image for running the kubernetes cluster
- To match base package versions such as the Ubuntu version with your real environment, you have to build the base/node images yourself following the KIND docs.
- The
k8s_infomodule doesn’t fail when the resource is missing; it returns an emptyresourceslist. So when verifying, check the length ofresources, notfailed. - PS. The
community.kubernetescollection was later renamed tokubernetes.core, so on recent versions use the new collection name.