Giter Club home page Giter Club logo

ansible-k0s's Introduction

Ansible Role: k0s

Create a Kubernetes Cluster using Ansible.

Use vanilla upstream Kubernetes distro k0s.

Similar to movd/k0s-ansible, but better (i think so ;) )

GitHub Workflow Status GitHub issues GitHub release (latest by date) Ansible Downloads

If latest is set for k0s_version, the role tries to install the latest release version.
Please use this with caution, as incompatibilities between releases may occur!

The binaries are installed below /usr/local/bin/k0s/${k0s_version} and later linked to /usr/bin.
This should make it possible to downgrade relatively safely.

The k0s archive is stored on the Ansible controller, unpacked and then the binaries are copied to the target system. The cache directory can be defined via the environment variable CUSTOM_LOCAL_TMP_DIRECTORY.
By default it is ${HOME}/.cache/ansible/k0s.
If this type of installation is not desired, the download can take place directly on the target system.
However, this must be explicitly activated by setting k0s_direct_download to true.

Requirements & Dependencies

Ansible Collections

ansible-galaxy collection install bodsch.core
ansible-galaxy collection install bodsch.scm

or

ansible-galaxy collection install --requirements-file collections.yml

Why better?

This Ansible role can be used atomically.
If no changes are necessary, none will be made.

Avoid command calls.
Wherever possible, separate Ansible modules are used for this.

One role for all cases.

supported Operating systems

Tested on

  • ArchLinux
  • Debian based
    • Debian 10 / 11

working implementation

The example of a working implementation can be viewed at GitLab.
A suitable infrastructure based on KVM and Terraform can be created in the repository.

There are some tests in molecule that could be used. For reasons that are not clear to me, the tests in a docker container are not very meaningful. I have therefore extended the tests with the Vagrant driver.

There is a Makefile to start the tests:

make test -e TOX_SCENARIO=multi-worker
make test -e TOX_SCENARIO=vagrant-multi-worker

Contribution

Please read Contribution

Development, Branches (Git Tags)

The master Branch is my Working Horse includes the "latest, hot shit" and can be complete broken!

If you want to use something stable, please use a Tagged Version!

usage

k0s_version: 1.25.2+k0s.0
k0s_release_download_url: https://github.com/k0sproject/k0s/releases

k0s_system_user: k0s
k0s_system_group: k0s

k0s_config_dir: /etc/k0s
k0s_data_dir: /var/lib/k0s
k0s_libexec_dir: /usr/libexec/k0s

k0s_direct_download: false

k0s_worker_on_controller: false

k0s_force: false
k0s_debug: false
k0s_verbose: false

k0s_cluster_nodes:
  initial_controller: ""
  controllers: []
  workers: []

k0s_extra_arguments:
  controller:
    - --enable-metrics-scraper

k0s_config_overwrites: {}

k0s_token_expiry: "15m"

k0s_artifacts_dir: "{{ inventory_dir }}/artifacts"

k0s_config_overwrites

Extension of the automatically created k0s.yaml The structure must correspond to the created configuration. An example file can be viewed here.

single controller

k0s_cluster_nodes:
  initial_controller: controller-1.k0s.local
  controllers: []
  workers: []

one controller with multi workers

k0s_cluster_nodes:
  initial_controller: controller-1.k0s.local
  controllers: []
  workers:
    - worker-1.k0s.local
    - worker-2.k0s.local
    - worker-3.k0s.local

multi controllers with multi workers

k0s_cluster_nodes:
  initial_controller: controller-1.k0s.local
  controllers:
    - controller-2.k0s.local
    - controller-3.k0s.local
  workers:
    - worker-1.k0s.local
    - worker-2.k0s.local
    - worker-3.k0s.local

Credits

other dokumentaions

Upgrading a k0s cluster in-place from single-master to HA

ansible-k0s's People

Contributors

bodsch avatar garb4ge avatar yasn77 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ansible-k0s's Issues

Problem deploying additional controllers

When running your k0s role, the playbook runs into an error, that I am not able to debug.

Could you please take a look at it, I'm not sure why this error is happening or how to debug it properly.

Setup

Ansible Version:

ansible [core 2.13.4]
  config file = /home/kevin/workspace/adit/awx/ansible/ansible.cfg
  configured module search path = ['/home/kevin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/kevin/workspace/adit/awx/venv/lib/python3.10/site-packages/ansible
  ansible collection location = /home/kevin/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/kevin/workspace/adit/awx/venv/bin/ansible
  python version = 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]
  jinja version = 3.1.2
  libyaml = True

Playbook:

---
- hosts: all
  roles:
    - k0s

Group_Vars:

ansible_user: debian
k0s_cluster_nodes:
  initial_controller: "controller1"
  controllers: ["controller2", "controller3"]
  workers: ["worker1"]

Infrasetup:

  • 4 VMs
    • 3 Controllers
    • 1 Worker
  • OS: Debian 11

Problem

Expected behaviour

The role completes all necessary steps and sets up a complete cluster with k0s

Actual behavior

The cluster is created, but only with the initial_controller, the other controllers fail with the following error:

TASK [k0s : create k0s controller service with install command] ********************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
fatal: [controller3]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 10.40.131.234 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/debian/.ansible/tmp/ansible-tmp-1663931311.561756-27647-148094266551000/AnsiballZ_k0s_install.py\", line 107, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/debian/.ansible/tmp/ansible-tmp-1663931311.561756-27647-148094266551000/AnsiballZ_k0s_install.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/debian/.ansible/tmp/ansible-tmp-1663931311.561756-27647-148094266551000/AnsiballZ_k0s_install.py\", line 47, in invoke_module\r\n    runpy.run_module(mod_name='ansible.modules.k0s_install', init_globals=dict(_module_fqn='ansible.modules.k0s_install', _modlib_path=modlib_path),\r\n  File \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_k0s_install_payload_1_3z3zsv/ansible_k0s_install_payload.zip/ansible/modules/k0s_install.py\", line 240, in <module>\r\n  File \"/tmp/ansible_k0s_install_payload_1_3z3zsv/ansible_k0s_install_payload.zip/ansible/modules/k0s_install.py\", line 231, in main\r\n  File \"/tmp/ansible_k0s_install_payload_1_3z3zsv/ansible_k0s_install_payload.zip/ansible/modules/k0s_install.py\", line 59, in run\r\n  File \"/tmp/ansible_k0s_install_payload_1_3z3zsv/ansible_k0s_install_payload.zip/ansible/modules/k0s_install.py\", line 79, in k0s_install\r\n  File \"/usr/lib/python3.9/genericpath.py\", line 30, in isfile\r\n    st = os.stat(path)\r\nTypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
fatal: [controller2]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 10.40.131.89 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/debian/.ansible/tmp/ansible-tmp-1663931311.5873406-27649-115115981473066/AnsiballZ_k0s_install.py\", line 107, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/debian/.ansible/tmp/ansible-tmp-1663931311.5873406-27649-115115981473066/AnsiballZ_k0s_install.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/debian/.ansible/tmp/ansible-tmp-1663931311.5873406-27649-115115981473066/AnsiballZ_k0s_install.py\", line 47, in invoke_module\r\n    runpy.run_module(mod_name='ansible.modules.k0s_install', init_globals=dict(_module_fqn='ansible.modules.k0s_install', _modlib_path=modlib_path),\r\n  File \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_k0s_install_payload_z0_svte8/ansible_k0s_install_payload.zip/ansible/modules/k0s_install.py\", line 240, in <module>\r\n  File \"/tmp/ansible_k0s_install_payload_z0_svte8/ansible_k0s_install_payload.zip/ansible/modules/k0s_install.py\", line 231, in main\r\n  File \"/tmp/ansible_k0s_install_payload_z0_svte8/ansible_k0s_install_payload.zip/ansible/modules/k0s_install.py\", line 59, in run\r\n  File \"/tmp/ansible_k0s_install_payload_z0_svte8/ansible_k0s_install_payload.zip/ansible/modules/k0s_install.py\", line 79, in k0s_install\r\n  File \"/usr/lib/python3.9/genericpath.py\", line 30, in isfile\r\n    st = os.stat(path)\r\nTypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.