istvano.microk8s

Ansible Role: microk8s

This role helps you download and install microk8s, which is a lightweight and easy-to-use production-ready Kubernetes.

Requirements

  • Ansible version 2.7 or higher
  • A Linux distribution:
    • Debian Family
      • Ubuntu
        • Xenial (16.04)
        • Bionic (18.04)
        • Focal (20.04) (not tested)
        • Jammy (22.04) (not tested)
    • Arch Linux (not tested)

License

MIT

Usage

Role Variables

Here are some important variables you can use in this role. You can find all variables in [defaults/main.yml](defaults/main.yml).

  • microk8s_version: The version you want to use, which defaults to 1.27/stable.
  • microk8s_plugins: Turn various plugins on or off. Use a string for enabling an addon with name:arg.
  • microk8s_enable_HA: Turn high-availability on or off.
  • microk8s_group_HA: The group of hosts that will create the HA cluster.
  • microk8s_group_WORKERS: The group of hosts that will only act as worker nodes (no control-plane components here).
  • microk8s_csr_template: If set, it will use a custom CSR when generating certificates.

Basic Playbook

Here is a simple example of how to use this role in a playbook:

- hosts: servers
  roles:
    - role: istvano.microk8s
      vars:
        microk8s_plugins:
          dns: "1.1.1.1"
          istio: true
          ingress: true

Note: When changing the list of plugins, it's best to copy the entire list from defaults/main.yml to avoid any issues in the deployment.

Custom Certificate Request Template

You can customize the certificate request template used by MicroK8s. This can be useful for adding extra Subject Alternative Names (SANs) to the certificates so they can be validated from outside the cluster, like through a reverse proxy.

To create a CSR template, run the role without a template first. After that, copy the CSR found in /var/snap/microk8s/current/certs/csr.conf.template to your playbook's templates directory, make your changes, set the microk8s_csr_template variable, and run the playbook again.

Adding Worker Nodes (1.23+ Only)

You can set up additional nodes to only act as workers in your MicroK8s cluster. This is done by configuring the Ansible hostgroup microk8s_WORKERS (you can change the group name using microk8s_group_WORKERS). Every host in this group will run microk8s join .... --worker. For more information, check out: microk8s-clustering.

Testing

Using Molecule Wrapper with System Python

Run these commands:

  • ./moleculew lint
  • ./moleculew create
  • ./moleculew list
  • ./moleculew check
  • ./moleculew test

Using Python Virtual Environment

  1. Create a virtual environment:
    $ python3 -m venv venv
    
  2. Activate the environment:
    $ . venv/bin/activate
    
  3. Install Molecule with linting and Docker options:
    $ pip install 'molecule[lint,docker]'
    
  4. Install the latest Ansible package if needed:
    $ pip install ansible
    
  5. Run the test commands:
  • molecule lint
  • molecule create
  • molecule list
  • molecule check
  • molecule test
Informazioni sul progetto

Ansible role for installing and set-up microk8s.

Installa
ansible-galaxy install istvano.microk8s
Licenza
mit
Download
31.6k
Proprietario