{"id":29195421,"url":"https://github.com/sudo-kraken/k3s-cluster-maintenance","last_synced_at":"2026-05-02T18:40:53.815Z","repository":{"id":301718678,"uuid":"1010094415","full_name":"sudo-kraken/k3s-cluster-maintenance","owner":"sudo-kraken","description":"🚀 Automated K3s cluster maintenance with Ansible - safely maintain nodes one at a time with health checks, Longhorn support, and master node protection. Sequential processing ensures cluster stability during updates and reboots.","archived":false,"fork":false,"pushed_at":"2025-06-28T11:56:34.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-28T12:22:35.858Z","etag":null,"topics":["ansible","ansible-playbook","bash","bash-script","bash-scripting","bashrc","k3s","k3s-cluster","kubernetes"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sudo-kraken.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-28T10:30:02.000Z","updated_at":"2025-06-28T11:56:37.000Z","dependencies_parsed_at":"2025-06-28T12:22:46.145Z","dependency_job_id":null,"html_url":"https://github.com/sudo-kraken/k3s-cluster-maintenance","commit_stats":null,"previous_names":["sudo-kraken/k3s-cluster-maintenance"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sudo-kraken/k3s-cluster-maintenance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudo-kraken%2Fk3s-cluster-maintenance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudo-kraken%2Fk3s-cluster-maintenance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudo-kraken%2Fk3s-cluster-maintenance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudo-kraken%2Fk3s-cluster-maintenance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sudo-kraken","download_url":"https://codeload.github.com/sudo-kraken/k3s-cluster-maintenance/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudo-kraken%2Fk3s-cluster-maintenance/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263077630,"owners_count":23410167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-playbook","bash","bash-script","bash-scripting","bashrc","k3s","k3s-cluster","kubernetes"],"created_at":"2025-07-02T05:04:23.100Z","updated_at":"2026-05-02T18:40:53.795Z","avatar_url":"https://github.com/sudo-kraken.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"docs/assets/logo.png\" align=\"center\" width=\"144px\" height=\"144px\"/\u003e\n\n### K3s Cluster Maintenance\n\n_A modular Ansible role and playbook that performs automated operating system patching and system maintenance on K3s cluster nodes with zero-downtime semantics. Designed for local runs or CI runners._\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![Ansible](https://img.shields.io/badge/Ansible-Required-red.svg?style=for-the-badge)](https://ansible.com) [![Ansible Version](https://img.shields.io/badge/Ansible-2.14%2B-blue?logo=ansible\u0026style=for-the-badge)](https://docs.ansible.com/) \n\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![OpenSSF Scorecard](https://img.shields.io/ossf-scorecard/github.com/sudo-kraken/k3s-cluster-maintenance?label=openssf%20scorecard\u0026style=for-the-badge)](https://scorecard.dev/viewer/?uri=github.com/sudo-kraken/k3s-cluster-maintenance)\n\n\u003c/div\u003e\n\n## Contents\n\n- [Overview](#overview)\n- [Architecture at a glance](#architecture-at-a-glance)\n  - [Role structure](#role-structure)\n  - [Group variables](#group-variables)\n- [Features](#features)\n- [Prerequisites](#prerequisites)\n- [Quick start](#quick-start)\n- [Configuration](#configuration)\n  - [Role variables](#role-variables)\n  - [Inventory structure](#inventory-structure)\n  - [Repository contents](#repository-contents)\n  - [Tag reference](#tag-reference)\n- [Health](#health)\n- [Endpoint](#endpoint)\n- [Production notes](#production-notes)\n- [Development](#development)\n- [Troubleshooting](#troubleshooting)\n- [Licence](#licence)\n- [Security](#security)\n- [Contributing](#contributing)\n- [Support](#support)\n- [Disclaimer](#disclaimer)\n\n## Overview\n\nEnterprise-grade automation for K3s clusters that safely applies system updates, security patches and package upgrades across master and worker nodes without impacting availability. Operations are orchestrated through a production-ready Ansible role that handles draining, reboots and post-update restoration.\n\n## Architecture at a glance\n\n- Modular Ansible role with `maintenance.yml` as the entry point\n- Sequential node processing for zero-downtime\n- Smart detection to skip when no updates are available\n- Longhorn-aware storage health checks and recovery waits\n- Robust reboot handling with adaptive wait logic\n- Group-based configuration via `group_vars`\n\n### Role structure\n\n```\nroles/\n  k3s_node_maintenance/\n    ├── tasks/\n    │   ├── main.yml                 # Main task orchestration\n    │   ├── prerequisites.yml        # Pre-flight checks\n    │   ├── package_checks.yml       # Update detection\n    │   ├── cluster_preparation.yml  # Node draining\n    │   ├── package_updates.yml      # OS updates\n    │   ├── debian_updates.yml       # Debian/Ubuntu specific\n    │   ├── redhat_updates.yml       # RHEL/CentOS specific\n    │   ├── reboot_handling.yml      # Reboot coordination\n    │   └── cluster_restoration.yml  # Node restoration\n    ├── defaults/\n    │   └── main.yml                 # Default variables\n    ├── handlers/\n    │   └── main.yml                 # Event handlers\n    └── meta/\n        └── main.yml                 # Role metadata\n```\n\n### Group variables\n\n```\ngroup_vars/\n  ├── k3s_masters/main.yml   # Master-specific settings\n  ├── k3s_workers/main.yml   # Worker-specific settings\n  ├── os_debian/main.yml     # Debian/Ubuntu settings\n  └── os_redhat/main.yml     # RHEL/CentOS settings\n```\n\n## Features\n\n- Automated OS patching: system updates, security patches and package upgrades\n- Zero-downtime operations via safe, sequential node handling\n- Intelligent detection that exits early when no updates are required\n- Health monitoring across nodes, control plane and storage\n- Native Longhorn integration with volume health verification and recovery waits\n- Control plane safety with quorum-aware master handling\n- Smart reboot management that adapts to node boot speeds\n- Enterprise-ready modular role for scalability and customisation\n\n## Prerequisites\n\n- K3s cluster, single or multi-node\n- Ansible 2.9 or newer, tested with 2.14.x\n- kubectl configured for your cluster\n- SSH access to all nodes with key-based authentication\n- `kubernetes.core` Ansible collection\n- Python Kubernetes client for API operations\n\n## Quick start\n\nRun maintenance using simple Ansible commands:\n\n```bash\n# Update all worker nodes\nansible-playbook -i hosts.yml maintenance.yml --limit k3s_workers\n\n# Update all master nodes\nansible-playbook -i hosts.yml maintenance.yml --limit k3s_masters\n\n# Update a specific node\nansible-playbook -i hosts.yml maintenance.yml --limit node-01\n\n# Update the entire cluster\nansible-playbook -i hosts.yml maintenance.yml\n```\n\n## Configuration\n\n### Role variables\n\nCustomise behaviour through group variables.\n\n```yaml\n# group_vars/k3s_masters/main.yml\nk3s_node_maintenance_drain_timeout: 600\nk3s_node_maintenance_wait_timeout: 1800\nk3s_node_maintenance_skip_drain: true  # Masters are not drained\n\n# group_vars/k3s_workers/main.yml\nk3s_node_maintenance_drain_timeout: 300\nk3s_node_maintenance_wait_timeout: 600\nk3s_node_maintenance_skip_drain: false\n\n# group_vars/os_debian/main.yml\nk3s_node_maintenance_package_manager: apt\nk3s_node_maintenance_cache_valid_time: 3600\n\n# group_vars/os_redhat/main.yml\nk3s_node_maintenance_package_manager: dnf\nk3s_node_maintenance_needs_restarting_available: true\n```\n\n### Inventory structure\n\nDefine your cluster in `hosts.yml`:\n\n```yaml\nall:\n  children:\n    k3s_cluster:\n      children:\n        k3s_masters:\n          hosts:\n            master-01:\n              ansible_host: 10.0.0.100\n            master-02:\n              ansible_host: 10.0.0.101\n            master-03:\n              ansible_host: 10.0.0.102\n        k3s_workers:\n          hosts:\n            worker-01:\n              ansible_host: 10.0.0.150\n            worker-02:\n              ansible_host: 10.0.0.151\n        os_debian:\n          hosts:\n            master-01:\n            worker-01:\n        os_redhat:\n          hosts:\n            master-02:\n            master-03:\n            worker-02:\n```\n\n### Repository contents\n\n| File | Description |\n|------|-------------|\n| `maintenance.yml` | Main playbook using enterprise role architecture |\n| `hosts.yml.example` | Example inventory with group structure |\n| `ansible.cfg` | Ansible configuration |\n| `roles/` | Modular role architecture |\n| `group_vars/` | Node type and OS-specific variables |\n| `requirements.txt` | Python dependencies |\n\n### Tag reference\n\n| Tag | Description | Use case |\n|-----|-------------|----------|\n| `prerequisites` | Pre-flight checks | Validate environment setup |\n| `check_updates` | Package update detection | See what updates are available |\n| `prepare` | Cluster preparation | Cordon and drain nodes only |\n| `packages` | All package operations | Package management only |\n| `updates` | Package installation | Install updates only |\n| `reboot` | Reboot coordination | Reboot handling only |\n| `restore` | Cluster restoration | Uncordon and restore scheduling |\n| `resume` | Manual recovery | Resume after failures including restore |\n| `uncordon` | Node uncordoning | Restore node scheduling only |\n| `debian` | Debian or Ubuntu only | OS-specific operations |\n| `redhat` | RHEL or CentOS only | OS-specific operations |\n| `longhorn` | Longhorn operations | Storage-specific tasks |\n\n## Health\n\n- Pre-flight validation of cluster prerequisites and connectivity\n- Node readiness checks before and after maintenance\n- Control plane validation for API server and etcd on masters\n- Longhorn volume health checks and recovery waits when available\n\n## Endpoint\n\nThis project is an Ansible automation, not a network service.\n\n- Primary entry point: `maintenance.yml`\n- Invoke with `ansible-playbook -i hosts.yml maintenance.yml` and the tags or limits that fit your scenario\n\n## Production notes\n\n- Process nodes sequentially to preserve availability\n- Keep timeouts conservative to match your node boot and image pull times\n- Use `check_updates` to avoid unnecessary work when no updates are available\n- When using Longhorn, allow time for degraded volumes to become healthy before proceeding\n- Keep `k3s_node_maintenance_skip_drain` set appropriately for masters to protect quorum\n\n## Development\n\n```bash\n# 1) Clone\ngit clone https://github.com/sudo-kraken/k3s-cluster-maintenance.git\ncd k3s-cluster-maintenance\n\n# 2) Install Python deps\npip install -r requirements.txt\n\n# 3) Install Ansible collections\nansible-galaxy collection install kubernetes.core\n# or from the file if present\nansible-galaxy collection install -r collections/requirements.yml\n\n# 4) Configure inventory\ncp hosts.yml.example hosts.yml\n# edit hosts.yml with your cluster details\n\n# 5) Test connectivity\nansible all -i hosts.yml -m ping\n```\n\n## Troubleshooting\n\n- Verify available updates\n  ```bash\n  ansible all -i hosts.yml -m package_facts\n  ```\n- Check cluster health\n  ```bash\n  kubectl get nodes\n  kubectl get pods --all-namespaces\n  ```\n- Verify Longhorn status if applicable\n  ```bash\n  kubectl get pods -n longhorn-system\n  ```\n\nCommon issues\n\n- No updates needed  \n  Normal behaviour. The role skips maintenance when no packages need updating.\n\n- Node not ready after maintenance\n  ```bash\n  kubectl get nodes\n  kubectl uncordon \u003cnode-name\u003e\n  ```\n\n- Ansible connection issues\n  ```bash\n  ansible all -i hosts.yml -m ping\n  ssh user@node-ip\n  ```\n\nDebug mode\n\n```bash\nansible-playbook -i hosts.yml maintenance.yml -vvv\nansible-playbook -i hosts.yml maintenance.yml --list-tags\nansible-playbook -i hosts.yml maintenance.yml --tags check_updates --check\nansible-playbook -i hosts.yml maintenance.yml --limit node-01 --tags resume\n```\n\n## Licence\n\nThis project is licensed under the MIT Licence. See the [LICENCE](LICENCE) file for details.\n\n## Security\n\nIf you discover a security issue, please review and follow the guidance in [SECURITY.md](SECURITY.md), or open a private security-focused issue with minimal details and request a secure contact channel.\n\n## Contributing\n\nFeel free to open issues or submit pull requests if you have suggestions or improvements.\nSee [CONTRIBUTING.md](CONTRIBUTING.md)\n\n## Support\n\nOpen an [issue](/../../issues) with as much detail as possible, including your Ansible version, distribution details and relevant playbook output.\n\n## Disclaimer\n\nThis tool performs maintenance operations on your Kubernetes cluster. Always:\n- Test in a non-production environment first\n- Ensure you have recent backups\n- Review the role tasks before deployment\n- Monitor the process during execution\n\nUse at your own risk. I am not responsible for any damage or data loss.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudo-kraken%2Fk3s-cluster-maintenance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsudo-kraken%2Fk3s-cluster-maintenance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudo-kraken%2Fk3s-cluster-maintenance/lists"}