/ansible-collection-kubernetes

Ansible collection for deploying Kubernetes

Primary LanguageShellApache License 2.0Apache-2.0

Ansible Collection for Kubernetes

Gitlab pipeline status GitHub release GitHub license Ansible Collection

Ansible collection for deploying Kubernetes.

This Ansible collection provides Ansible playbooks and roles for the deployment and configuration of an Kubernetes environment.

Requirements

This collection require Ansible 2.10 or higher.

This collection was designed for:

  • Ubuntu 18.04, 20.04, 20.10
  • CentOS 7, 8, 8 Stream
  • openSUSE Leap 15.2, Tumbleweed
  • Debian 10
  • Fedora 33
  • RHEL 7, 8

Quick Start

Bootstrap Ansible and Roles

Start by cloning the repository, checkout the corresponding branch, and init with git submodule, then bootstrap Python3 + Ansible with provided helper script:

# GIT clone the development branch
git clone --branch develop https://github.com/alvistack/ansible-collection-kubernetes
cd ansible-collection-kubernetes

# Setup Roles with GIT submodule
git submodule init
git submodule sync
git submodule update

# Bootstrap Ansible
./scripts/bootstrap-ansible.sh

# Confirm the version of Python3, PIP3 and Ansible
python3 --version
pip3 --version
ansible --version

AIO

All-in-one (AIO) build is a great way to perform an Kubernetes build for:

  • A development environment
  • An overview of how all the Kubernetes services fit together
  • A simple lab deployment

Simply execule our default Molecule test case and it will deploy all default components into your localhost:

# Run Molecule test case
molecule test -s default

# Confirm the version and status of Kubernetes
kubectl version
kubectl get node --output wide
kubectl get pod --all-namespaces

Production

In order to avoid Single Point of Failure, at least 3 instances for Kubernetes is recommended.

For production environment we should backed with Ceph File System for Kubernetes Persistent Volumes with ReadWriteMany support. Corresponding dynamic provisioning could be handled by using CSI CephFS.

Traditionally we could use Docker or containerd as Kubernetes container runtime (CRI). Now a day, this collection is default with the modern CRI-O implementation.

Moreover, we are using Weave Net as Kubernetes network plugin (CNI) so we could support Kubernetes Network Policies.

This deployment will setup the follow components:

Start by copying the default inventory for customization:

# Copy default inventory
cp -rfp inventory/default inventory/myinventory

You should update the following files as per your production environment:

- `inventory/myinventory/hosts`
  - Update with your inventory hostnames and IPs
- `inventory/myinventory/group_vars/all/00-defaults.yml`
  - Update `*_release` and `*_version` if you hope to pin the deployment into any legacy supported version

Once update now run the playbooks:

# Run playbooks
ansible-playbook -i inventory/myinventory/hosts playbooks/converge.yml

# Confirm the version and status of Kubernetes
kubectl version
kubectl get node --output wide
kubectl get pod --all-namespaces

Molecule

You could also run our Molecule test cases if you have Vagrant and Libvirt installed, e.g.

# Bootstrap Vagrant and Libvirt
./scripts/bootstrap-vagrant.sh

# Run Molecule on Ubuntu 20.04
molecule converge -s ubuntu-20.04

Please refer to .travis.yml for more information on running Molecule.

License

Author Information