v0.0.3
This commit is contained in:
parent
6413ee32c2
commit
b8348de27a
@ -1,20 +1,3 @@
|
|||||||
---
|
---
|
||||||
# Group vars for Kubernetes control plane nodes
|
# Group vars for Kubernetes control plane nodes
|
||||||
kubernetes_role: control_plane
|
kubernetes_role: control_plane
|
||||||
iptables_forward_policy: ACCEPT
|
|
||||||
iptables_open_ports:
|
|
||||||
- interface: any
|
|
||||||
protocol: tcp
|
|
||||||
port: 6443
|
|
||||||
- interface: any
|
|
||||||
protocol: tcp
|
|
||||||
port: '2379:2380'
|
|
||||||
- interface: any
|
|
||||||
protocol: tcp
|
|
||||||
port: 10250
|
|
||||||
- interface: any
|
|
||||||
protocol: tcp
|
|
||||||
port: 10257
|
|
||||||
- interface: any
|
|
||||||
protocol: tcp
|
|
||||||
port: 10259
|
|
||||||
|
@ -1,14 +1,3 @@
|
|||||||
---
|
---
|
||||||
# Group vars for Kubernetes worker nodes
|
# Group vars for Kubernetes worker nodes
|
||||||
kubernetes_role: node
|
kubernetes_role: node
|
||||||
iptables_forward_policy: ACCEPT
|
|
||||||
iptables_open_ports:
|
|
||||||
- interface: any
|
|
||||||
protocol: tcp
|
|
||||||
port: 10250
|
|
||||||
- interface: any
|
|
||||||
protocol: tcp
|
|
||||||
port: 10256
|
|
||||||
- interface: any
|
|
||||||
protocol: tcp
|
|
||||||
port: "30000:32767"
|
|
||||||
|
4
roles/geerlingguy.containerd/.ansible-lint
Normal file
4
roles/geerlingguy.containerd/.ansible-lint
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
skip_list:
|
||||||
|
- 'yaml'
|
||||||
|
- 'risky-shell-pipe'
|
||||||
|
- 'role-name'
|
4
roles/geerlingguy.containerd/.github/FUNDING.yml
vendored
Normal file
4
roles/geerlingguy.containerd/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
---
|
||||||
|
github: geerlingguy
|
||||||
|
patreon: geerlingguy
|
57
roles/geerlingguy.containerd/.github/stale.yml
vendored
Normal file
57
roles/geerlingguy.containerd/.github/stale.yml
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# Configuration for probot-stale - https://github.com/probot/stale
|
||||||
|
---
|
||||||
|
# Number of days of inactivity before an Issue or Pull Request becomes stale
|
||||||
|
daysUntilStale: 90
|
||||||
|
|
||||||
|
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
|
||||||
|
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
|
||||||
|
daysUntilClose: 30
|
||||||
|
|
||||||
|
# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
|
||||||
|
onlyLabels: []
|
||||||
|
|
||||||
|
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
||||||
|
exemptLabels:
|
||||||
|
- bug
|
||||||
|
- pinned
|
||||||
|
- security
|
||||||
|
- planned
|
||||||
|
|
||||||
|
# Set to true to ignore issues in a project (defaults to false)
|
||||||
|
exemptProjects: false
|
||||||
|
|
||||||
|
# Set to true to ignore issues in a milestone (defaults to false)
|
||||||
|
exemptMilestones: false
|
||||||
|
|
||||||
|
# Set to true to ignore issues with an assignee (defaults to false)
|
||||||
|
exemptAssignees: false
|
||||||
|
|
||||||
|
# Label to use when marking as stale
|
||||||
|
staleLabel: stale
|
||||||
|
|
||||||
|
# Limit the number of actions per hour, from 1-30. Default is 30
|
||||||
|
limitPerRun: 30
|
||||||
|
|
||||||
|
pulls:
|
||||||
|
markComment: |-
|
||||||
|
This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!
|
||||||
|
|
||||||
|
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark pull requests as stale.
|
||||||
|
|
||||||
|
unmarkComment: >-
|
||||||
|
This pull request is no longer marked for closure.
|
||||||
|
|
||||||
|
closeComment: >-
|
||||||
|
This pull request has been closed due to inactivity. If you feel this is in error, please reopen the pull request or file a new PR with the relevant details.
|
||||||
|
|
||||||
|
issues:
|
||||||
|
markComment: |-
|
||||||
|
This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
|
||||||
|
|
||||||
|
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale.
|
||||||
|
|
||||||
|
unmarkComment: >-
|
||||||
|
This issue is no longer marked for closure.
|
||||||
|
|
||||||
|
closeComment: >-
|
||||||
|
This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.
|
69
roles/geerlingguy.containerd/.github/workflows/ci.yml
vendored
Normal file
69
roles/geerlingguy.containerd/.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
---
|
||||||
|
name: CI
|
||||||
|
'on':
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
schedule:
|
||||||
|
- cron: "0 7 * * 0"
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: 'geerlingguy.containerd'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out the codebase.
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.containerd'
|
||||||
|
|
||||||
|
- name: Set up Python 3.
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install test dependencies.
|
||||||
|
run: pip3 install yamllint
|
||||||
|
|
||||||
|
- name: Lint code.
|
||||||
|
run: |
|
||||||
|
yamllint .
|
||||||
|
|
||||||
|
molecule:
|
||||||
|
name: Molecule
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
distro:
|
||||||
|
- rockylinux8
|
||||||
|
- centos7
|
||||||
|
- ubuntu2004
|
||||||
|
- debian11
|
||||||
|
- fedora35
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out the codebase.
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.containerd'
|
||||||
|
|
||||||
|
- name: Set up Python 3.
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install test dependencies.
|
||||||
|
run: pip3 install ansible molecule[docker] docker
|
||||||
|
|
||||||
|
- name: Run Molecule tests.
|
||||||
|
run: molecule test
|
||||||
|
env:
|
||||||
|
PY_COLORS: '1'
|
||||||
|
ANSIBLE_FORCE_COLOR: '1'
|
||||||
|
MOLECULE_DISTRO: ${{ matrix.distro }}
|
40
roles/geerlingguy.containerd/.github/workflows/release.yml
vendored
Normal file
40
roles/geerlingguy.containerd/.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
# This workflow requires a GALAXY_API_KEY secret present in the GitHub
|
||||||
|
# repository or organization.
|
||||||
|
#
|
||||||
|
# See: https://github.com/marketplace/actions/publish-ansible-role-to-galaxy
|
||||||
|
# See: https://github.com/ansible/galaxy/issues/46
|
||||||
|
|
||||||
|
name: Release
|
||||||
|
'on':
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: 'geerlingguy.containerd'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
release:
|
||||||
|
name: Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out the codebase.
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.containerd'
|
||||||
|
|
||||||
|
- name: Set up Python 3.
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install Ansible.
|
||||||
|
run: pip3 install ansible-core
|
||||||
|
|
||||||
|
- name: Trigger a new import on Galaxy.
|
||||||
|
run: >-
|
||||||
|
ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }}
|
||||||
|
$(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2)
|
5
roles/geerlingguy.containerd/.gitignore
vendored
Normal file
5
roles/geerlingguy.containerd/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
*.retry
|
||||||
|
*/__pycache__
|
||||||
|
*.pyc
|
||||||
|
.cache
|
||||||
|
|
11
roles/geerlingguy.containerd/.yamllint
Normal file
11
roles/geerlingguy.containerd/.yamllint
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 200
|
||||||
|
level: warning
|
||||||
|
|
||||||
|
ignore: |
|
||||||
|
.github/stale.yml
|
||||||
|
.travis.yml
|
20
roles/geerlingguy.containerd/LICENSE
Normal file
20
roles/geerlingguy.containerd/LICENSE
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2021 Jeff Geerling
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
65
roles/geerlingguy.containerd/README.md
Normal file
65
roles/geerlingguy.containerd/README.md
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# Ansible Role: Containerd
|
||||||
|
|
||||||
|
[](https://github.com/geerlingguy/ansible-role-containerd/actions?query=workflow%3ACI)
|
||||||
|
|
||||||
|
An Ansible Role that installs [containerd](https://containerd.io) on Linux.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
## Role Variables
|
||||||
|
|
||||||
|
Available variables are listed below, along with default values (see `defaults/main.yml`):
|
||||||
|
|
||||||
|
containerd_package: containerd.io
|
||||||
|
containerd_package_state: present
|
||||||
|
|
||||||
|
Package name and state controls.
|
||||||
|
|
||||||
|
containerd_service_state: started
|
||||||
|
containerd_service_enabled: true
|
||||||
|
|
||||||
|
Service controls. You can install containerd but not have it running or enabled on boot by changing these defaults.
|
||||||
|
|
||||||
|
containerd_config_default_write: true
|
||||||
|
|
||||||
|
Write containerd defaults to the containerd config.toml file.
|
||||||
|
|
||||||
|
containerd_config_cgroup_driver_systemd: false
|
||||||
|
|
||||||
|
Set systemd as cgroup driver in config.toml. Only valid with `containerd_config_default_write: true`
|
||||||
|
|
||||||
|
docker_apt_release_channel: stable
|
||||||
|
docker_apt_arch: '{{ (ansible_architecture == "aarch64") | ternary("arm64", "amd64") }}'
|
||||||
|
docker_apt_repository: "deb [arch={{ docker_apt_arch }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}"
|
||||||
|
docker_apt_ignore_key_error: true
|
||||||
|
docker_apt_gpg_key: https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg
|
||||||
|
|
||||||
|
Apt installation paramemeters, useful if you want to switch from the stable channel releases, or install on a different CPU architecture (e.g. `arm64`).
|
||||||
|
|
||||||
|
docker_yum_repo_url: https://download.docker.com/linux/{{ (ansible_distribution == "Fedora") | ternary("fedora","centos") }}/docker-ce.repo
|
||||||
|
docker_yum_repo_enable_nightly: '0'
|
||||||
|
docker_yum_gpg_key: https://download.docker.com/linux/centos/gpg
|
||||||
|
|
||||||
|
Yum/DNF installation parameters, useful if you want to switch from the stable repository.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
## Example Playbook
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- hosts: all
|
||||||
|
roles:
|
||||||
|
- geerlingguy.containerd
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT / BSD
|
||||||
|
|
||||||
|
## Author Information
|
||||||
|
|
||||||
|
This role was created in 2021 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
|
27
roles/geerlingguy.containerd/defaults/main.yml
Normal file
27
roles/geerlingguy.containerd/defaults/main.yml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
# Package options.
|
||||||
|
containerd_package: containerd.io
|
||||||
|
containerd_package_state: present
|
||||||
|
|
||||||
|
# Service options.
|
||||||
|
containerd_service_state: started
|
||||||
|
containerd_service_enabled: true
|
||||||
|
|
||||||
|
# Write a default containerd config.toml file.
|
||||||
|
containerd_config_default_write: true
|
||||||
|
|
||||||
|
# Set systemd as cgroup driver in config.toml
|
||||||
|
# Only use with containerd_config_default_write: true
|
||||||
|
containerd_config_cgroup_driver_systemd: true
|
||||||
|
|
||||||
|
# Used only for Debian/Ubuntu. Switch 'stable' to 'nightly' if needed.
|
||||||
|
docker_apt_release_channel: stable
|
||||||
|
docker_apt_arch: '{{ (ansible_architecture == "aarch64") | ternary("arm64", "amd64") }}'
|
||||||
|
docker_apt_repository: "deb [arch={{ docker_apt_arch }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}"
|
||||||
|
docker_apt_ignore_key_error: true
|
||||||
|
docker_apt_gpg_key: https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg
|
||||||
|
|
||||||
|
# Used only for RedHat/CentOS/Fedora.
|
||||||
|
docker_yum_repo_url: https://download.docker.com/linux/{{ (ansible_distribution == "Fedora") | ternary("fedora","centos") }}/docker-ce.repo
|
||||||
|
docker_yum_repo_enable_nightly: '0'
|
||||||
|
docker_yum_gpg_key: https://download.docker.com/linux/centos/gpg
|
5
roles/geerlingguy.containerd/handlers/main.yml
Normal file
5
roles/geerlingguy.containerd/handlers/main.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: restart containerd
|
||||||
|
service:
|
||||||
|
name: containerd
|
||||||
|
state: restarted
|
2
roles/geerlingguy.containerd/meta/.galaxy_install_info
Normal file
2
roles/geerlingguy.containerd/meta/.galaxy_install_info
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
install_date: Wed Jul 3 15:51:21 2024
|
||||||
|
version: 1.3.1
|
35
roles/geerlingguy.containerd/meta/main.yml
Normal file
35
roles/geerlingguy.containerd/meta/main.yml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
---
|
||||||
|
dependencies: []
|
||||||
|
|
||||||
|
galaxy_info:
|
||||||
|
role_name: containerd
|
||||||
|
author: geerlingguy
|
||||||
|
description: containerd.io for Linux.
|
||||||
|
company: "Midwestern Mac, LLC"
|
||||||
|
license: "license (BSD, MIT)"
|
||||||
|
min_ansible_version: 2.8
|
||||||
|
platforms:
|
||||||
|
- name: EL
|
||||||
|
versions:
|
||||||
|
- 7
|
||||||
|
- 8
|
||||||
|
- name: Fedora
|
||||||
|
versions:
|
||||||
|
- all
|
||||||
|
- name: Debian
|
||||||
|
versions:
|
||||||
|
- stretch
|
||||||
|
- buster
|
||||||
|
- name: Ubuntu
|
||||||
|
versions:
|
||||||
|
- xenial
|
||||||
|
- bionic
|
||||||
|
- focal
|
||||||
|
galaxy_tags:
|
||||||
|
- system
|
||||||
|
- containers
|
||||||
|
- docker
|
||||||
|
- containerd
|
||||||
|
- kubernetes
|
||||||
|
- orchestration
|
||||||
|
- server
|
24
roles/geerlingguy.containerd/molecule/default/converge.yml
Normal file
24
roles/geerlingguy.containerd/molecule/default/converge.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
|
||||||
|
pre_tasks:
|
||||||
|
- name: Update apt cache.
|
||||||
|
apt: update_cache=yes cache_valid_time=600
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- name: Wait for systemd to complete initialization. # noqa 303
|
||||||
|
command: systemctl is-system-running
|
||||||
|
register: systemctl_status
|
||||||
|
until: >
|
||||||
|
'running' in systemctl_status.stdout or
|
||||||
|
'degraded' in systemctl_status.stdout
|
||||||
|
retries: 30
|
||||||
|
delay: 5
|
||||||
|
when: ansible_service_mgr == 'systemd'
|
||||||
|
changed_when: false
|
||||||
|
failed_when: systemctl_status.rc > 1
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: geerlingguy.containerd
|
18
roles/geerlingguy.containerd/molecule/default/molecule.yml
Normal file
18
roles/geerlingguy.containerd/molecule/default/molecule.yml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
role_name_check: 1
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
platforms:
|
||||||
|
- name: instance
|
||||||
|
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
|
||||||
|
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||||
|
volumes:
|
||||||
|
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||||
|
privileged: true
|
||||||
|
pre_build_image: true
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
playbooks:
|
||||||
|
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
|
71
roles/geerlingguy.containerd/tasks/main.yml
Normal file
71
roles/geerlingguy.containerd/tasks/main.yml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
---
|
||||||
|
- include_tasks: setup-RedHat.yml
|
||||||
|
when: ansible_os_family == 'RedHat'
|
||||||
|
|
||||||
|
- include_tasks: setup-Debian.yml
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- name: Ensure containerd is installed.
|
||||||
|
package:
|
||||||
|
name: "{{ containerd_package }}"
|
||||||
|
state: "{{ containerd_package_state }}"
|
||||||
|
|
||||||
|
- name: Ensure containerd is started and enabled at boot.
|
||||||
|
service:
|
||||||
|
name: containerd
|
||||||
|
state: "{{ containerd_service_state }}"
|
||||||
|
enabled: "{{ containerd_service_enabled }}"
|
||||||
|
|
||||||
|
- name: Ensure containerd config directory exists.
|
||||||
|
file:
|
||||||
|
path: /etc/containerd
|
||||||
|
state: directory
|
||||||
|
register: containerd_dir
|
||||||
|
|
||||||
|
- name: Get defaults from containerd.
|
||||||
|
command: containerd config default
|
||||||
|
changed_when: false
|
||||||
|
register: containerd_config_default
|
||||||
|
when: containerd_config_default_write
|
||||||
|
|
||||||
|
- name: Prepare containerd/config.toml from default config
|
||||||
|
copy:
|
||||||
|
dest: /tmp/containerd_config.toml
|
||||||
|
content: "{{ containerd_config_default.stdout }}"
|
||||||
|
when: containerd_config_default_write
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Set Cgroup driver to systemd
|
||||||
|
lineinfile:
|
||||||
|
insertafter: '.*\[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options\]$'
|
||||||
|
line: ' SystemdCgroup = true'
|
||||||
|
state: present
|
||||||
|
path: /tmp/containerd_config.toml
|
||||||
|
when: containerd_config_default_write and containerd_config_cgroup_driver_systemd
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Make sure SystemdCgroup = false is not set
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: /tmp/containerd_config.toml
|
||||||
|
state: absent
|
||||||
|
line: ' SystemdCgroup = false'
|
||||||
|
notify: restart containerd
|
||||||
|
when: containerd_config_default_write and containerd_config_cgroup_driver_systemd
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Copy config.toml to /etc/containerd
|
||||||
|
copy:
|
||||||
|
remote_src: true
|
||||||
|
src: /tmp/containerd_config.toml
|
||||||
|
dest: /etc/containerd/config.toml
|
||||||
|
notify: restart containerd
|
||||||
|
when: containerd_config_default_write
|
||||||
|
|
||||||
|
- name: Cleanup temporary file
|
||||||
|
file:
|
||||||
|
path: /tmp/containerd_config.toml
|
||||||
|
state: absent
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Ensure containerd is restarted immediately if necessary.
|
||||||
|
meta: flush_handlers
|
31
roles/geerlingguy.containerd/tasks/setup-Debian.yml
Normal file
31
roles/geerlingguy.containerd/tasks/setup-Debian.yml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure dependencies are installed.
|
||||||
|
apt:
|
||||||
|
name:
|
||||||
|
- apt-transport-https
|
||||||
|
- ca-certificates
|
||||||
|
- gnupg2
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Add Docker apt key.
|
||||||
|
apt_key:
|
||||||
|
url: "{{ docker_apt_gpg_key }}"
|
||||||
|
id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
|
||||||
|
state: present
|
||||||
|
register: add_repository_key
|
||||||
|
ignore_errors: "{{ docker_apt_ignore_key_error }}"
|
||||||
|
|
||||||
|
- name: Ensure curl is present (on older systems without SNI).
|
||||||
|
package: name=curl state=present
|
||||||
|
when: add_repository_key is failed
|
||||||
|
|
||||||
|
- name: Add Docker apt key (alternative for older systems without SNI).
|
||||||
|
shell: >
|
||||||
|
curl -sSL {{ docker_apt_gpg_key }} | sudo apt-key add -
|
||||||
|
when: add_repository_key is failed
|
||||||
|
|
||||||
|
- name: Add Docker repository.
|
||||||
|
apt_repository:
|
||||||
|
repo: "{{ docker_apt_repository }}"
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
26
roles/geerlingguy.containerd/tasks/setup-RedHat.yml
Normal file
26
roles/geerlingguy.containerd/tasks/setup-RedHat.yml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
- name: Add Docker GPG key.
|
||||||
|
rpm_key:
|
||||||
|
key: "{{ docker_yum_gpg_key }}"
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Add Docker repository.
|
||||||
|
get_url:
|
||||||
|
url: "{{ docker_yum_repo_url }}"
|
||||||
|
dest: '/etc/yum.repos.d/docker-ce.repo'
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
|
|
||||||
|
- name: Configure Docker Nightly repo.
|
||||||
|
ini_file:
|
||||||
|
dest: '/etc/yum.repos.d/docker-ce.repo'
|
||||||
|
section: 'docker-ce-nightly'
|
||||||
|
option: enabled
|
||||||
|
value: '{{ docker_yum_repo_enable_nightly }}'
|
||||||
|
mode: 0644
|
||||||
|
|
||||||
|
- name: Ensure container-selinux is installed.
|
||||||
|
package:
|
||||||
|
name: container-selinux
|
||||||
|
state: present
|
4
roles/geerlingguy.kubernetes/.ansible-lint
Normal file
4
roles/geerlingguy.kubernetes/.ansible-lint
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
skip_list:
|
||||||
|
- 'yaml'
|
||||||
|
- 'risky-shell-pipe'
|
||||||
|
- 'role-name'
|
4
roles/geerlingguy.kubernetes/.github/FUNDING.yml
vendored
Normal file
4
roles/geerlingguy.kubernetes/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
---
|
||||||
|
github: geerlingguy
|
||||||
|
patreon: geerlingguy
|
74
roles/geerlingguy.kubernetes/.github/workflows/ci.yml
vendored
Normal file
74
roles/geerlingguy.kubernetes/.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
---
|
||||||
|
name: CI
|
||||||
|
'on':
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
schedule:
|
||||||
|
- cron: "0 4 * * 3"
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: 'geerlingguy.kubernetes'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out the codebase.
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.kubernetes'
|
||||||
|
|
||||||
|
- name: Set up Python 3.
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install test dependencies.
|
||||||
|
run: pip3 install yamllint
|
||||||
|
|
||||||
|
- name: Lint code.
|
||||||
|
run: |
|
||||||
|
yamllint .
|
||||||
|
|
||||||
|
molecule:
|
||||||
|
name: Molecule
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- distro: rockylinux8
|
||||||
|
playbook: converge.yml
|
||||||
|
- distro: ubuntu2004
|
||||||
|
playbook: converge.yml
|
||||||
|
- distro: debian11
|
||||||
|
playbook: converge.yml
|
||||||
|
|
||||||
|
- distro: debian11
|
||||||
|
playbook: calico.yml
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out the codebase.
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.kubernetes'
|
||||||
|
|
||||||
|
- name: Set up Python 3.
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install test dependencies.
|
||||||
|
run: pip3 install ansible molecule molecule-plugins[docker] docker
|
||||||
|
|
||||||
|
- name: Run Molecule tests.
|
||||||
|
run: molecule test
|
||||||
|
env:
|
||||||
|
PY_COLORS: '1'
|
||||||
|
ANSIBLE_FORCE_COLOR: '1'
|
||||||
|
MOLECULE_DISTRO: ${{ matrix.distro }}
|
||||||
|
MOLECULE_PLAYBOOK: ${{ matrix.playbook }}
|
40
roles/geerlingguy.kubernetes/.github/workflows/release.yml
vendored
Normal file
40
roles/geerlingguy.kubernetes/.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
# This workflow requires a GALAXY_API_KEY secret present in the GitHub
|
||||||
|
# repository or organization.
|
||||||
|
#
|
||||||
|
# See: https://github.com/marketplace/actions/publish-ansible-role-to-galaxy
|
||||||
|
# See: https://github.com/ansible/galaxy/issues/46
|
||||||
|
|
||||||
|
name: Release
|
||||||
|
'on':
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: 'geerlingguy.kubernetes'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
release:
|
||||||
|
name: Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out the codebase.
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.kubernetes'
|
||||||
|
|
||||||
|
- name: Set up Python 3.
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install Ansible.
|
||||||
|
run: pip3 install ansible-core
|
||||||
|
|
||||||
|
- name: Trigger a new import on Galaxy.
|
||||||
|
run: >-
|
||||||
|
ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }}
|
||||||
|
$(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2)
|
34
roles/geerlingguy.kubernetes/.github/workflows/stale.yml
vendored
Normal file
34
roles/geerlingguy.kubernetes/.github/workflows/stale.yml
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
name: Close inactive issues
|
||||||
|
'on':
|
||||||
|
schedule:
|
||||||
|
- cron: "55 3 * * 0" # semi-random time
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
close-issues:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/stale@v8
|
||||||
|
with:
|
||||||
|
days-before-stale: 120
|
||||||
|
days-before-close: 60
|
||||||
|
exempt-issue-labels: bug,pinned,security,planned
|
||||||
|
exempt-pr-labels: bug,pinned,security,planned
|
||||||
|
stale-issue-label: "stale"
|
||||||
|
stale-pr-label: "stale"
|
||||||
|
stale-issue-message: |
|
||||||
|
This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
|
||||||
|
|
||||||
|
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale.
|
||||||
|
close-issue-message: |
|
||||||
|
This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.
|
||||||
|
stale-pr-message: |
|
||||||
|
This pr has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
|
||||||
|
|
||||||
|
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale.
|
||||||
|
close-pr-message: |
|
||||||
|
This pr has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
5
roles/geerlingguy.kubernetes/.gitignore
vendored
Normal file
5
roles/geerlingguy.kubernetes/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
*.retry
|
||||||
|
*/__pycache__
|
||||||
|
*.pyc
|
||||||
|
.cache
|
||||||
|
|
10
roles/geerlingguy.kubernetes/.yamllint
Normal file
10
roles/geerlingguy.kubernetes/.yamllint
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 150
|
||||||
|
level: warning
|
||||||
|
|
||||||
|
ignore: |
|
||||||
|
.github/workflows/stale.yml
|
20
roles/geerlingguy.kubernetes/LICENSE
Normal file
20
roles/geerlingguy.kubernetes/LICENSE
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2018 Jeff Geerling
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
225
roles/geerlingguy.kubernetes/README.md
Normal file
225
roles/geerlingguy.kubernetes/README.md
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
# Ansible Role: Kubernetes
|
||||||
|
|
||||||
|
[](https://github.com/geerlingguy/ansible-role-kubernetes/actions?query=workflow%3ACI)
|
||||||
|
|
||||||
|
An Ansible Role that installs [Kubernetes](https://kubernetes.io) on Linux.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
Requires a compatible [Container Runtime](https://kubernetes.io/docs/setup/production-environment/container-runtimes); recommended role for CRI installation: `geerlingguy.containerd`.
|
||||||
|
|
||||||
|
## Role Variables
|
||||||
|
|
||||||
|
Available variables are listed below, along with default values (see `defaults/main.yml`):
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_packages:
|
||||||
|
- name: kubelet
|
||||||
|
state: present
|
||||||
|
- name: kubectl
|
||||||
|
state: present
|
||||||
|
- name: kubeadm
|
||||||
|
state: present
|
||||||
|
- name: kubernetes-cni
|
||||||
|
state: present
|
||||||
|
```
|
||||||
|
|
||||||
|
Kubernetes packages to be installed on the server. You can either provide a list of package names, or set `name` and `state` to have more control over whether the package is `present`, `absent`, `latest`, etc.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_version: '1.25'
|
||||||
|
kubernetes_version_rhel_package: '1.25.1'
|
||||||
|
```
|
||||||
|
|
||||||
|
The minor version of Kubernetes to install. The plain `kubernetes_version` is used to pin an apt package version on Debian, and as the Kubernetes version passed into the `kubeadm init` command (see `kubernetes_version_kubeadm`). The `kubernetes_version_rhel_package` variable must be a specific Kubernetes release, and is used to pin the version on Red Hat / CentOS servers.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_role: control_plane
|
||||||
|
```
|
||||||
|
|
||||||
|
Whether the particular server will serve as a Kubernetes `control_plane` (default) or `node`. The control plane will have `kubeadm init` run on it to intialize the entire K8s control plane, while `node`s will have `kubeadm join` run on them to join them to the `control_plane`.
|
||||||
|
|
||||||
|
### Variables to configure kubeadm and kubelet with `kubeadm init` through a config file (recommended)
|
||||||
|
|
||||||
|
With this role, `kubeadm init` will be run with `--config <FILE>`.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_kubeadm_kubelet_config_file_path: '/etc/kubernetes/kubeadm-kubelet-config.yaml'
|
||||||
|
```
|
||||||
|
|
||||||
|
Path for `<FILE>`. If the directory does not exist, this role will create it.
|
||||||
|
|
||||||
|
The following variables are parsed as options to <FILE>. To understand its syntax, see [kubelet-integration](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/kubelet-integration) and [kubeadm-config-file](https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/#config-file) . The skeleton (`apiVersion`, `kind`) of the config file will be created by this role, so do not define them within the variables. (See `templates/kubeadm-kubelet-config.j2`).
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_config_init_configuration:
|
||||||
|
localAPIEndpoint:
|
||||||
|
advertiseAddress: "{{ kubernetes_apiserver_advertise_address | default(ansible_default_ipv4.address, true) }}"
|
||||||
|
```
|
||||||
|
|
||||||
|
Defines the options under `kind: InitConfiguration`. Including `kubernetes_apiserver_advertise_address` here is for backward-compatibilty to older versions of this role, where `kubernetes_apiserver_advertise_address` was used with a command-line-option.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_config_cluster_configuration:
|
||||||
|
networking:
|
||||||
|
podSubnet: "{{ kubernetes_pod_network.cidr }}"
|
||||||
|
kubernetesVersion: "{{ kubernetes_version_kubeadm }}"
|
||||||
|
```
|
||||||
|
|
||||||
|
Options under `kind: ClusterConfiguration`. Including `kubernetes_pod_network.cidr` and `kubernetes_version_kubeadm` here are for backward-compatibilty to older versions of this role, where they were used with command-line-options.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_config_kubelet_configuration:
|
||||||
|
cgroupDriver: systemd
|
||||||
|
```
|
||||||
|
|
||||||
|
Options to configure kubelet on any nodes in your cluster through the `kubeadm init` process. For syntax options read the [kubelet config file](https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file) and [kubelet integration](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/kubelet-integration) documentation.
|
||||||
|
|
||||||
|
NOTE: This is the recommended way to do the kubelet-configuration. Most command-line-options are deprecated.
|
||||||
|
|
||||||
|
NOTE: The recommended cgroupDriver depends on your [Container Runtime](https://kubernetes.io/docs/setup/production-environment/container-runtimes). When using this role with Docker instead of containerd, this value should be changed to `cgroupfs`.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_config_kube_proxy_configuration: {}
|
||||||
|
```
|
||||||
|
|
||||||
|
Options to configure kubelet's proxy configuration in the `KubeProxyConfiguration` section of the kubelet configuration.
|
||||||
|
|
||||||
|
### Variables to configure kubeadm and kubelet through command-line-options
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_kubelet_extra_args: ""
|
||||||
|
kubernetes_kubelet_extra_args_config_file: /etc/default/kubelet
|
||||||
|
```
|
||||||
|
|
||||||
|
Extra args to pass to `kubelet` during startup. E.g. to allow `kubelet` to start up even if there is swap is enabled on your server, set this to: `"--fail-swap-on=false"`. Or to specify the node-ip advertised by `kubelet`, set this to `"--node-ip={{ ansible_host }}"`. **This option is deprecated. Please use `kubernetes_config_kubelet_configuration` instead.**
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_kubeadm_init_extra_opts: ""
|
||||||
|
```
|
||||||
|
|
||||||
|
Extra args to pass to `kubeadm init` during K8s control plane initialization. E.g. to specify extra Subject Alternative Names for API server certificate, set this to: `"--apiserver-cert-extra-sans my-custom.host"`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_join_command_extra_opts: ""
|
||||||
|
```
|
||||||
|
|
||||||
|
Extra args to pass to the generated `kubeadm join` command during K8s node initialization. E.g. to ignore certain preflight errors like swap being enabled, set this to: `--ignore-preflight-errors=Swap`
|
||||||
|
|
||||||
|
### Additional variables
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_allow_pods_on_control_plane: true
|
||||||
|
```
|
||||||
|
|
||||||
|
Whether to remove the taint that denies pods from being deployed to the Kubernetes control plane. If you have a single-node cluster, this should definitely be `True`. Otherwise, set to `False` if you want a dedicated Kubernetes control plane which doesn't run any other pods.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_pod_network:
|
||||||
|
# Flannel CNI.
|
||||||
|
cni: 'flannel'
|
||||||
|
cidr: '10.244.0.0/16'
|
||||||
|
#
|
||||||
|
# Calico CNI.
|
||||||
|
# cni: 'calico'
|
||||||
|
# cidr: '192.168.0.0/16'
|
||||||
|
#
|
||||||
|
# Weave CNI.
|
||||||
|
# cni: 'weave'
|
||||||
|
# cidr: '192.168.0.0/16'
|
||||||
|
```
|
||||||
|
|
||||||
|
This role currently supports `flannel` (default), `calico` or `weave` for cluster pod networking. Choose only one for your cluster; converting between them is not done automatically and could result in broken networking; if you need to switch from one to another, it should be done outside of this role.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_apiserver_advertise_address: ''`
|
||||||
|
kubernetes_version_kubeadm: 'stable-{{ kubernetes_version }}'`
|
||||||
|
kubernetes_ignore_preflight_errors: 'all'
|
||||||
|
```
|
||||||
|
|
||||||
|
Options passed to `kubeadm init` when initializing the Kubernetes control plane. The `kubernetes_apiserver_advertise_address` defaults to `ansible_default_ipv4.address` if it's left empty.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_apt_release_channel: "stable"
|
||||||
|
kubernetes_apt_keyring_file: "/etc/apt/keyrings/kubernetes-apt-keyring.asc"
|
||||||
|
kubernetes_apt_repository: "deb [signed-by={{ kubernetes_apt_keyring_file }}] https://pkgs.k8s.io/core:/{{ kubernetes_apt_release_channel }}:/v{{ kubernetes_version }}/deb/ /"
|
||||||
|
```
|
||||||
|
|
||||||
|
Apt repository options for Kubernetes installation.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_yum_base_url: "https://pkgs.k8s.io/core:/stable:/v{{ kubernetes_version }}/rpm/"
|
||||||
|
kubernetes_yum_gpg_key: "https://pkgs.k8s.io/core:/stable:/v{{ kubernetes_version }}/rpm/repodata/repomd.xml.key"
|
||||||
|
kubernetes_yum_gpg_check: true
|
||||||
|
kubernetes_yum_repo_gpg_check: true
|
||||||
|
```
|
||||||
|
|
||||||
|
Yum repository options for Kubernetes installation. You can change `kubernete_yum_gpg_key` to a different url if you are behind a firewall or provide a trustworthy mirror. Usually in combination with changing `kubernetes_yum_base_url` as well.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_flannel_manifest_file: https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
Flannel manifest file to apply to the Kubernetes cluster to enable networking. You can copy your own files to your server and apply them instead, if you need to customize the Flannel networking configuration.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_calico_manifest_file: https://projectcalico.docs.tigera.io/manifests/calico.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
Calico manifest file to apply to the Kubernetes cluster (if using Calico instead of Flannel).
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
## Example Playbooks
|
||||||
|
|
||||||
|
### Single node (control-plane-only) cluster
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- hosts: all
|
||||||
|
|
||||||
|
vars:
|
||||||
|
kubernetes_allow_pods_on_control_plane: true
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- geerlingguy.docker
|
||||||
|
- geerlingguy.kubernetes
|
||||||
|
```
|
||||||
|
|
||||||
|
### Two or more nodes (single control-plane) cluster
|
||||||
|
|
||||||
|
Control plane inventory vars:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_role: "control_plane"
|
||||||
|
```
|
||||||
|
|
||||||
|
Node(s) inventory vars:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_role: "node"
|
||||||
|
```
|
||||||
|
|
||||||
|
Playbook:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- hosts: all
|
||||||
|
|
||||||
|
vars:
|
||||||
|
kubernetes_allow_pods_on_control_plane: true
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- geerlingguy.docker
|
||||||
|
- geerlingguy.kubernetes
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, log into the Kubernetes control plane, and run `kubectl get nodes` as root, and you should see a list of all the servers.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT / BSD
|
||||||
|
|
||||||
|
## Author Information
|
||||||
|
|
||||||
|
This role was created in 2018 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
|
67
roles/geerlingguy.kubernetes/defaults/main.yml
Normal file
67
roles/geerlingguy.kubernetes/defaults/main.yml
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
---
|
||||||
|
kubernetes_packages:
|
||||||
|
- name: kubelet
|
||||||
|
state: present
|
||||||
|
- name: kubectl
|
||||||
|
state: present
|
||||||
|
- name: kubeadm
|
||||||
|
state: present
|
||||||
|
- name: kubernetes-cni
|
||||||
|
state: present
|
||||||
|
|
||||||
|
kubernetes_version: '1.25'
|
||||||
|
kubernetes_version_rhel_package: '1.25.1'
|
||||||
|
|
||||||
|
kubernetes_role: "{{ kubernetes_role }}"
|
||||||
|
|
||||||
|
# This is deprecated. Please use kubernetes_config_kubelet_configuration instead.
|
||||||
|
kubernetes_kubelet_extra_args: ""
|
||||||
|
|
||||||
|
kubernetes_kubeadm_init_extra_opts: ""
|
||||||
|
kubernetes_join_command_extra_opts: ""
|
||||||
|
kubernetes_allow_pods_on_control_plane: true
|
||||||
|
kubernetes_pod_network:
|
||||||
|
# Flannel CNI.
|
||||||
|
cni: 'flannel'
|
||||||
|
cidr: '10.{{ ipv4_subnet }}.0.0/16'
|
||||||
|
# Calico CNI.
|
||||||
|
# cni: 'calico'
|
||||||
|
# cidr: '192.168.0.0/16'
|
||||||
|
|
||||||
|
kubernetes_kubeadm_kubelet_config_file_path: '/etc/kubernetes/kubeadm-kubelet-config.yaml'
|
||||||
|
kubernetes_config_kubelet_configuration:
|
||||||
|
cgroupDriver: "systemd"
|
||||||
|
|
||||||
|
kubernetes_config_init_configuration:
|
||||||
|
localAPIEndpoint:
|
||||||
|
advertiseAddress: "{{ kubernetes_apiserver_advertise_address | default(ansible_default_ipv4.address, true) }}"
|
||||||
|
# if you use the next lines, remove the command line argument below
|
||||||
|
# nodeRegistration:
|
||||||
|
# ignorePreflightErrors:
|
||||||
|
# - all
|
||||||
|
|
||||||
|
kubernetes_config_cluster_configuration:
|
||||||
|
networking:
|
||||||
|
podSubnet: "{{ kubernetes_pod_network.cidr }}"
|
||||||
|
kubernetesVersion: "{{ kubernetes_version_kubeadm }}"
|
||||||
|
|
||||||
|
kubernetes_config_kube_proxy_configuration: {}
|
||||||
|
|
||||||
|
kubernetes_apiserver_advertise_address: ''
|
||||||
|
kubernetes_version_kubeadm: 'stable-{{ kubernetes_version }}'
|
||||||
|
kubernetes_ignore_preflight_errors: 'all'
|
||||||
|
|
||||||
|
kubernetes_apt_release_channel: "stable"
|
||||||
|
kubernetes_apt_keyring_file: "/etc/apt/keyrings/kubernetes-apt-keyring.asc"
|
||||||
|
kubernetes_apt_repository: "deb [signed-by={{ kubernetes_apt_keyring_file }}] https://pkgs.k8s.io/core:/{{ kubernetes_apt_release_channel }}:/v{{ kubernetes_version }}/deb/ /"
|
||||||
|
|
||||||
|
kubernetes_yum_base_url: "https://pkgs.k8s.io/core:/stable:/v{{ kubernetes_version }}/rpm/"
|
||||||
|
kubernetes_yum_gpg_key: "https://pkgs.k8s.io/core:/stable:/v{{ kubernetes_version }}/rpm/repodata/repomd.xml.key"
|
||||||
|
kubernetes_yum_gpg_check: true
|
||||||
|
kubernetes_yum_repo_gpg_check: true
|
||||||
|
|
||||||
|
# Flannel config file.
|
||||||
|
kubernetes_flannel_manifest_file: https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
|
||||||
|
|
||||||
|
# Calico config file.
|
||||||
|
kubernetes_calico_manifest_file: https://projectcalico.docs.tigera.io/manifests/calico.yaml
|
3
roles/geerlingguy.kubernetes/handlers/main.yml
Normal file
3
roles/geerlingguy.kubernetes/handlers/main.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
- name: restart kubelet
|
||||||
|
service: name=kubelet state=restarted
|
2
roles/geerlingguy.kubernetes/meta/.galaxy_install_info
Normal file
2
roles/geerlingguy.kubernetes/meta/.galaxy_install_info
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
install_date: Wed Jul 3 15:52:54 2024
|
||||||
|
version: 8.0.0
|
33
roles/geerlingguy.kubernetes/meta/main.yml
Normal file
33
roles/geerlingguy.kubernetes/meta/main.yml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
---
|
||||||
|
dependencies: []
|
||||||
|
|
||||||
|
galaxy_info:
|
||||||
|
role_name: kubernetes
|
||||||
|
author: geerlingguy
|
||||||
|
description: Kubernetes for Linux.
|
||||||
|
company: "Midwestern Mac, LLC"
|
||||||
|
license: "license (BSD, MIT)"
|
||||||
|
min_ansible_version: 2.10
|
||||||
|
platforms:
|
||||||
|
- name: Debian
|
||||||
|
versions:
|
||||||
|
- stretch
|
||||||
|
- buster
|
||||||
|
- bullseye
|
||||||
|
- name: Ubuntu
|
||||||
|
versions:
|
||||||
|
- xenial
|
||||||
|
- bionic
|
||||||
|
- focal
|
||||||
|
- jammy
|
||||||
|
galaxy_tags:
|
||||||
|
- system
|
||||||
|
- containers
|
||||||
|
- docker
|
||||||
|
- rkt
|
||||||
|
- orchestration
|
||||||
|
- kubernetes
|
||||||
|
- k8s
|
||||||
|
- paas
|
||||||
|
- saas
|
||||||
|
- hosting
|
54
roles/geerlingguy.kubernetes/molecule/default/calico.yml
Normal file
54
roles/geerlingguy.kubernetes/molecule/default/calico.yml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
|
||||||
|
vars:
|
||||||
|
kubernetes_pod_network:
|
||||||
|
cni: 'calico'
|
||||||
|
cidr: '192.168.0.0/16'
|
||||||
|
|
||||||
|
# Allow swap in test environments (hard to control in some envs).
|
||||||
|
kubernetes_config_kubelet_configuration:
|
||||||
|
cgroupDriver: "systemd"
|
||||||
|
failSwapOn: false
|
||||||
|
cgroupsPerQOS: true
|
||||||
|
enforceNodeAllocatable: ['pods']
|
||||||
|
containerd_config_cgroup_driver_systemd: true
|
||||||
|
|
||||||
|
pre_tasks:
|
||||||
|
- name: Update apt cache.
|
||||||
|
apt: update_cache=true cache_valid_time=600
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- name: Ensure test dependencies are installed (RedHat).
|
||||||
|
package: name=iproute state=present
|
||||||
|
when: ansible_os_family == 'RedHat'
|
||||||
|
|
||||||
|
- name: Ensure test dependencies are installed (Debian).
|
||||||
|
package: name=iproute2 state=present
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- name: Gather facts.
|
||||||
|
action: setup
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: geerlingguy.containerd
|
||||||
|
- role: geerlingguy.kubernetes
|
||||||
|
|
||||||
|
post_tasks:
|
||||||
|
- name: Get cluster info.
|
||||||
|
command: kubectl cluster-info
|
||||||
|
changed_when: false
|
||||||
|
register: kubernetes_info
|
||||||
|
|
||||||
|
- name: Print cluster info.
|
||||||
|
debug: var=kubernetes_info.stdout
|
||||||
|
|
||||||
|
- name: Get all running pods.
|
||||||
|
command: kubectl get pods --all-namespaces
|
||||||
|
changed_when: false
|
||||||
|
register: kubernetes_pods
|
||||||
|
|
||||||
|
- name: Print list of running pods.
|
||||||
|
debug: var=kubernetes_pods.stdout
|
50
roles/geerlingguy.kubernetes/molecule/default/converge.yml
Normal file
50
roles/geerlingguy.kubernetes/molecule/default/converge.yml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
|
||||||
|
vars:
|
||||||
|
# Allow swap in test environments (hard to control in some envs).
|
||||||
|
kubernetes_config_kubelet_configuration:
|
||||||
|
cgroupDriver: "systemd"
|
||||||
|
failSwapOn: false
|
||||||
|
cgroupsPerQOS: true
|
||||||
|
enforceNodeAllocatable: ['pods']
|
||||||
|
containerd_config_cgroup_driver_systemd: true
|
||||||
|
|
||||||
|
pre_tasks:
|
||||||
|
- name: Update apt cache.
|
||||||
|
apt: update_cache=true cache_valid_time=600
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- name: Ensure test dependencies are installed (RedHat).
|
||||||
|
package: name=iproute state=present
|
||||||
|
when: ansible_os_family == 'RedHat'
|
||||||
|
|
||||||
|
- name: Ensure test dependencies are installed (Debian).
|
||||||
|
package: name=iproute2 state=present
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- name: Gather facts.
|
||||||
|
action: setup
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: geerlingguy.containerd
|
||||||
|
- role: geerlingguy.kubernetes
|
||||||
|
|
||||||
|
post_tasks:
|
||||||
|
- name: Get cluster info.
|
||||||
|
command: kubectl cluster-info
|
||||||
|
changed_when: false
|
||||||
|
register: kubernetes_info
|
||||||
|
|
||||||
|
- name: Print cluster info.
|
||||||
|
debug: var=kubernetes_info.stdout
|
||||||
|
|
||||||
|
- name: Get all running pods.
|
||||||
|
command: kubectl get pods --all-namespaces
|
||||||
|
changed_when: false
|
||||||
|
register: kubernetes_pods
|
||||||
|
|
||||||
|
- name: Print list of running pods.
|
||||||
|
debug: var=kubernetes_pods.stdout
|
22
roles/geerlingguy.kubernetes/molecule/default/molecule.yml
Normal file
22
roles/geerlingguy.kubernetes/molecule/default/molecule.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
role_name_check: 1
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
options:
|
||||||
|
ignore-errors: true
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
platforms:
|
||||||
|
- name: instance
|
||||||
|
image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux8}-ansible:latest"
|
||||||
|
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||||
|
volumes:
|
||||||
|
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||||
|
- /var/lib/containerd
|
||||||
|
cgroupns_mode: host
|
||||||
|
privileged: true
|
||||||
|
pre_build_image: true
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
playbooks:
|
||||||
|
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
|
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
- src: geerlingguy.containerd
|
89
roles/geerlingguy.kubernetes/tasks/control-plane-setup.yml
Normal file
89
roles/geerlingguy.kubernetes/tasks/control-plane-setup.yml
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
---
|
||||||
|
- name: Create the directory for the kubernetes_config_file
|
||||||
|
file:
|
||||||
|
path: "{{ kubernetes_kubeadm_kubelet_config_file_path | dirname }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Deploy the config-file for kubeadm and kubelet
|
||||||
|
template:
|
||||||
|
src: "kubeadm-kubelet-config.j2"
|
||||||
|
dest: "{{ kubernetes_kubeadm_kubelet_config_file_path }}"
|
||||||
|
|
||||||
|
- name: Initialize Kubernetes control plane with kubeadm init
|
||||||
|
command: >
|
||||||
|
kubeadm init
|
||||||
|
--config {{ kubernetes_kubeadm_kubelet_config_file_path }}
|
||||||
|
{{ kubernetes_kubeadm_init_extra_opts }}
|
||||||
|
register: kubeadmin_init
|
||||||
|
when: (not kubernetes_init_stat.stat.exists) and (kubernetes_ignore_preflight_errors is not defined)
|
||||||
|
|
||||||
|
- name: Initialize Kubernetes control plane with kubeadm init and ignore_preflight_errors
|
||||||
|
command: >
|
||||||
|
kubeadm init
|
||||||
|
--config {{ kubernetes_kubeadm_kubelet_config_file_path }}
|
||||||
|
--ignore-preflight-errors={{ kubernetes_ignore_preflight_errors }}
|
||||||
|
{{ kubernetes_kubeadm_init_extra_opts }}
|
||||||
|
register: kubeadmin_init
|
||||||
|
when: (not kubernetes_init_stat.stat.exists) and (kubernetes_ignore_preflight_errors is defined)
|
||||||
|
|
||||||
|
- name: Print the init output to screen.
|
||||||
|
debug:
|
||||||
|
var: kubeadmin_init.stdout
|
||||||
|
verbosity: 2
|
||||||
|
when: not kubernetes_init_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Ensure .kube directory exists.
|
||||||
|
file:
|
||||||
|
path: ~/.kube
|
||||||
|
state: directory
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
|
- name: Symlink the kubectl admin.conf to ~/.kube/conf.
|
||||||
|
file:
|
||||||
|
src: /etc/kubernetes/admin.conf
|
||||||
|
dest: ~/.kube/config
|
||||||
|
state: link
|
||||||
|
mode: 0644
|
||||||
|
|
||||||
|
- name: Configure Flannel networking.
|
||||||
|
command: "kubectl apply -f {{ kubernetes_flannel_manifest_file }}"
|
||||||
|
register: flannel_result
|
||||||
|
changed_when: "'created' in flannel_result.stdout"
|
||||||
|
when: kubernetes_pod_network.cni == 'flannel'
|
||||||
|
until: flannel_result is not failed
|
||||||
|
retries: 12
|
||||||
|
delay: 5
|
||||||
|
|
||||||
|
- name: Configure Calico networking.
|
||||||
|
command: "kubectl apply -f {{ kubernetes_calico_manifest_file }}"
|
||||||
|
register: calico_result
|
||||||
|
changed_when: "'created' in calico_result.stdout"
|
||||||
|
when: kubernetes_pod_network.cni == 'calico'
|
||||||
|
until: calico_result is not failed
|
||||||
|
retries: 12
|
||||||
|
delay: 5
|
||||||
|
|
||||||
|
- name: Get Kubernetes version for Weave installation.
|
||||||
|
shell: kubectl version | base64 | tr -d '\n'
|
||||||
|
changed_when: false
|
||||||
|
register: kubectl_version
|
||||||
|
when: kubernetes_pod_network.cni == 'weave'
|
||||||
|
until: kubectl_version is not failed
|
||||||
|
retries: 12
|
||||||
|
delay: 5
|
||||||
|
|
||||||
|
- name: Configure Weave networking.
|
||||||
|
command: "{{ item }}"
|
||||||
|
with_items:
|
||||||
|
- "kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version={{ kubectl_version.stdout_lines[0] }}"
|
||||||
|
register: weave_result
|
||||||
|
changed_when: "'created' in weave_result.stdout"
|
||||||
|
when: kubernetes_pod_network.cni == 'weave'
|
||||||
|
|
||||||
|
# TODO: Check if taint exists with something like `kubectl describe nodes`
|
||||||
|
# instead of using kubernetes_init_stat.stat.exists check.
|
||||||
|
- name: Allow pods on control plane (if configured).
|
||||||
|
command: "kubectl taint nodes --all node-role.kubernetes.io/control-plane-"
|
||||||
|
when:
|
||||||
|
- kubernetes_allow_pods_on_control_plane | bool
|
||||||
|
- not kubernetes_init_stat.stat.exists
|
42
roles/geerlingguy.kubernetes/tasks/kubelet-setup.yml
Normal file
42
roles/geerlingguy.kubernetes/tasks/kubelet-setup.yml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
# ---- DEPRECATED ----------------
|
||||||
|
#
|
||||||
|
# Most of the kubernetes_kubelet_extra_args are deprecated. See https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet for details.
|
||||||
|
# Use the kubernetes_kubelet_config variable instead, which will be used to create the kubelet config file.
|
||||||
|
|
||||||
|
- name: Check for existence of kubelet environment file. (deprecated)
|
||||||
|
stat:
|
||||||
|
path: '{{ kubelet_environment_file_path }}'
|
||||||
|
register: kubelet_environment_file
|
||||||
|
|
||||||
|
- name: Set facts for KUBELET_EXTRA_ARGS task if environment file exists. (deprecated)
|
||||||
|
set_fact:
|
||||||
|
kubelet_args_path: '{{ kubelet_environment_file_path }}'
|
||||||
|
kubelet_args_line: "{{ 'KUBELET_EXTRA_ARGS=' + kubernetes_kubelet_extra_args }}"
|
||||||
|
kubelet_args_regexp: '^KUBELET_EXTRA_ARGS='
|
||||||
|
when: kubelet_environment_file.stat.exists
|
||||||
|
|
||||||
|
- name: Set facts for KUBELET_EXTRA_ARGS task if environment file doesn't exist. (deprecated)
|
||||||
|
set_fact:
|
||||||
|
kubelet_args_path: '/etc/systemd/system/kubelet.service.d/10-kubeadm.conf'
|
||||||
|
kubelet_args_line: "{{ 'Environment=\"KUBELET_EXTRA_ARGS=' + kubernetes_kubelet_extra_args + '\"' }}"
|
||||||
|
kubelet_args_regexp: '^Environment="KUBELET_EXTRA_ARGS='
|
||||||
|
when: not kubelet_environment_file.stat.exists
|
||||||
|
|
||||||
|
- name: Configure KUBELET_EXTRA_ARGS. (deprecated)
|
||||||
|
lineinfile:
|
||||||
|
path: '{{ kubelet_args_path }}'
|
||||||
|
line: '{{ kubelet_args_line }}'
|
||||||
|
regexp: '{{ kubelet_args_regexp }}'
|
||||||
|
state: present
|
||||||
|
mode: 0644
|
||||||
|
register: kubelet_extra_args
|
||||||
|
when: kubernetes_kubelet_extra_args|length > 0
|
||||||
|
|
||||||
|
- name: Reload systemd unit if args were changed. (deprecated)
|
||||||
|
systemd:
|
||||||
|
state: restarted
|
||||||
|
daemon_reload: true
|
||||||
|
name: kubelet
|
||||||
|
when: kubelet_extra_args is changed
|
59
roles/geerlingguy.kubernetes/tasks/main.yml
Normal file
59
roles/geerlingguy.kubernetes/tasks/main.yml
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
---
|
||||||
|
- name: Include OS-specific variables.
|
||||||
|
include_vars: "{{ ansible_os_family }}.yml"
|
||||||
|
|
||||||
|
- include_tasks: setup-RedHat.yml
|
||||||
|
when: ansible_os_family == 'RedHat'
|
||||||
|
|
||||||
|
- include_tasks: setup-Debian.yml
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- name: Ensure dependencies are installed.
|
||||||
|
package: name=curl state=present
|
||||||
|
|
||||||
|
- name: Install Kubernetes packages.
|
||||||
|
package:
|
||||||
|
name: "{{ item.name | default(item) }}"
|
||||||
|
state: "{{ item.state | default('present') }}"
|
||||||
|
notify: restart kubelet
|
||||||
|
with_items: "{{ kubernetes_packages }}"
|
||||||
|
|
||||||
|
- include_tasks: sysctl-setup.yml
|
||||||
|
|
||||||
|
- include_tasks: kubelet-setup.yml # deprecated
|
||||||
|
when: kubernetes_kubelet_extra_args|length > 0
|
||||||
|
|
||||||
|
- name: Ensure kubelet is started and enabled at boot.
|
||||||
|
service:
|
||||||
|
name: kubelet
|
||||||
|
state: started
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
- name: Check if Kubernetes has already been initialized.
|
||||||
|
stat:
|
||||||
|
path: /etc/kubernetes/admin.conf
|
||||||
|
register: kubernetes_init_stat
|
||||||
|
|
||||||
|
# Set up control plane.
|
||||||
|
- include_tasks: control-plane-setup.yml
|
||||||
|
when: kubernetes_role == 'control_plane'
|
||||||
|
|
||||||
|
# Set up nodes.
|
||||||
|
- name: Get the kubeadm join command from the Kubernetes control plane.
|
||||||
|
command: kubeadm token create --print-join-command
|
||||||
|
changed_when: false
|
||||||
|
when: kubernetes_role == 'control_plane'
|
||||||
|
register: kubernetes_join_command_result
|
||||||
|
|
||||||
|
- name: Set the kubeadm join command globally.
|
||||||
|
set_fact:
|
||||||
|
kubernetes_join_command: >
|
||||||
|
{{ kubernetes_join_command_result.stdout }}
|
||||||
|
{{ kubernetes_join_command_extra_opts }}
|
||||||
|
when: kubernetes_join_command_result.stdout is defined
|
||||||
|
delegate_to: "{{ item }}"
|
||||||
|
delegate_facts: true
|
||||||
|
with_items: "{{ groups['all'] }}"
|
||||||
|
|
||||||
|
- include_tasks: node-setup.yml
|
||||||
|
when: kubernetes_role == 'node'
|
6
roles/geerlingguy.kubernetes/tasks/node-setup.yml
Normal file
6
roles/geerlingguy.kubernetes/tasks/node-setup.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- name: Join node to Kubernetes control plane.
|
||||||
|
shell: >
|
||||||
|
{{ kubernetes_join_command }}
|
||||||
|
creates=/etc/kubernetes/kubelet.conf
|
||||||
|
tags: ['skip_ansible_lint']
|
38
roles/geerlingguy.kubernetes/tasks/setup-Debian.yml
Normal file
38
roles/geerlingguy.kubernetes/tasks/setup-Debian.yml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure dependencies are installed.
|
||||||
|
apt:
|
||||||
|
name:
|
||||||
|
- apt-transport-https
|
||||||
|
- ca-certificates
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Prepare apt keyring directory.
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ kubernetes_apt_keyring_file | dirname }}"
|
||||||
|
state: directory
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
|
- name: Get Kubernetes apt key.
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: "https://pkgs.k8s.io/core:/{{ kubernetes_apt_release_channel }}:/v{{ kubernetes_version }}/deb/Release.key"
|
||||||
|
dest: "{{ kubernetes_apt_keyring_file }}"
|
||||||
|
mode: '0644'
|
||||||
|
force: true
|
||||||
|
|
||||||
|
- name: Be sure deprecated Kubernetes repository is absent.
|
||||||
|
file:
|
||||||
|
path: "/etc/apt/sources.list.d/apt_kubernetes_io.list"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Add Kubernetes repository.
|
||||||
|
ansible.builtin.apt_repository:
|
||||||
|
repo: "{{ kubernetes_apt_repository }}"
|
||||||
|
filename: pkgs_k8s_io
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
|
||||||
|
- name: Add Kubernetes apt preferences file to pin a version.
|
||||||
|
template:
|
||||||
|
src: apt-preferences-kubernetes.j2
|
||||||
|
dest: /etc/apt/preferences.d/kubernetes
|
||||||
|
mode: 0644
|
20
roles/geerlingguy.kubernetes/tasks/setup-RedHat.yml
Normal file
20
roles/geerlingguy.kubernetes/tasks/setup-RedHat.yml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure Kubernetes repository exists.
|
||||||
|
yum_repository:
|
||||||
|
name: kubernetes
|
||||||
|
description: Kubernetes
|
||||||
|
enabled: true
|
||||||
|
gpgcheck: "{{ kubernetes_yum_gpg_check }}"
|
||||||
|
repo_gpgcheck: "{{ kubernetes_yum_repo_gpg_check }}"
|
||||||
|
baseurl: "{{ kubernetes_yum_base_url }}"
|
||||||
|
gpgkey: "{{ kubernetes_yum_gpg_key }}"
|
||||||
|
|
||||||
|
- name: Add Kubernetes GPG keys.
|
||||||
|
rpm_key:
|
||||||
|
key: "{{ kubernetes_yum_gpg_key }}"
|
||||||
|
state: present
|
||||||
|
register: kubernetes_rpm_key
|
||||||
|
|
||||||
|
- name: Make cache if Kubernetes GPG key changed.
|
||||||
|
command: "yum -q makecache -y --disablerepo='*' --enablerepo='kubernetes'"
|
||||||
|
when: kubernetes_rpm_key is changed
|
21
roles/geerlingguy.kubernetes/tasks/sysctl-setup.yml
Normal file
21
roles/geerlingguy.kubernetes/tasks/sysctl-setup.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure procps is installed.
|
||||||
|
package:
|
||||||
|
name: "{{ procps_package }}"
|
||||||
|
state: present
|
||||||
|
when: >
|
||||||
|
ansible_distribution != 'Debian'
|
||||||
|
or ansible_distribution_major_version | int < 10
|
||||||
|
|
||||||
|
# See: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#letting-iptables-see-bridged-traffic
|
||||||
|
- name: Let iptables see bridged traffic.
|
||||||
|
sysctl:
|
||||||
|
name: "{{ item }}"
|
||||||
|
value: '1'
|
||||||
|
state: present
|
||||||
|
loop:
|
||||||
|
- net.bridge.bridge-nf-call-iptables
|
||||||
|
- net.bridge.bridge-nf-call-ip6tables
|
||||||
|
when: >
|
||||||
|
ansible_distribution != 'Debian'
|
||||||
|
or ansible_distribution_major_version | int < 10
|
@ -0,0 +1,11 @@
|
|||||||
|
Package: kubectl
|
||||||
|
Pin: version {{ kubernetes_version }}.*
|
||||||
|
Pin-Priority: 1000
|
||||||
|
|
||||||
|
Package: kubeadm
|
||||||
|
Pin: version {{ kubernetes_version }}.*
|
||||||
|
Pin-Priority: 1000
|
||||||
|
|
||||||
|
Package: kubelet
|
||||||
|
Pin: version {{ kubernetes_version }}.*
|
||||||
|
Pin-Priority: 1000
|
@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
apiVersion: kubeadm.k8s.io/v1beta3
|
||||||
|
kind: InitConfiguration
|
||||||
|
{{ kubernetes_config_init_configuration | to_nice_yaml }}
|
||||||
|
---
|
||||||
|
apiVersion: kubeadm.k8s.io/v1beta3
|
||||||
|
kind: ClusterConfiguration
|
||||||
|
{{ kubernetes_config_cluster_configuration | to_nice_yaml }}
|
||||||
|
{% if kubernetes_config_kubelet_configuration|length > 0 %}
|
||||||
|
---
|
||||||
|
apiVersion: kubelet.config.k8s.io/v1beta1
|
||||||
|
kind: KubeletConfiguration
|
||||||
|
{{ kubernetes_config_kubelet_configuration | to_nice_yaml }}
|
||||||
|
{% endif %}
|
||||||
|
{% if kubernetes_config_kube_proxy_configuration|length > 0 %}
|
||||||
|
---
|
||||||
|
apiVersion: kubeproxy.config.k8s.io/v1alpha1
|
||||||
|
kind: KubeProxyConfiguration
|
||||||
|
{{ kubernetes_config_kube_proxy_configuration | to_nice_yaml }}
|
||||||
|
{% endif %}
|
3
roles/geerlingguy.kubernetes/vars/Debian.yml
Normal file
3
roles/geerlingguy.kubernetes/vars/Debian.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
procps_package: procps
|
||||||
|
kubelet_environment_file_path: /etc/default/kubelet
|
3
roles/geerlingguy.kubernetes/vars/RedHat.yml
Normal file
3
roles/geerlingguy.kubernetes/vars/RedHat.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
procps_package: procps-ng
|
||||||
|
kubelet_environment_file_path: /etc/sysconfig/kubelet
|
9
site.yml
9
site.yml
@ -6,3 +6,12 @@
|
|||||||
roles:
|
roles:
|
||||||
- role: ericomeehan.save_initial_configuration
|
- role: ericomeehan.save_initial_configuration
|
||||||
- role: ericomeehan.configure_network
|
- role: ericomeehan.configure_network
|
||||||
|
|
||||||
|
- name: Configure Kubernetes clusters
|
||||||
|
hosts: clusters
|
||||||
|
become: true
|
||||||
|
roles:
|
||||||
|
- role: geerlingguy.containerd
|
||||||
|
- role: geerlingguy.kubernetes
|
||||||
|
kubernetes_role: "{{ kubernetes_role }}"
|
||||||
|
ipv4_subnet: "{{ ipv4_subnet }}"
|
||||||
|
Loading…
Reference in New Issue
Block a user