Compare commits

...

124 Commits

Author SHA1 Message Date
Jeff Geerling
83e86bb88b
Merge pull request #166 from vivian-hafener/master
Moves apiversions for kubeadm, kubelet, and kubeproxy from kubeadm-kubelet-config.j2 into defaults/main.yml
2025-07-26 20:03:13 -07:00
Vivian Hafener
321375f702 Moves apiversions for kubeadm, kubelet, and proxy
apiVersions for kubeadm, the kubelet, and the kubeproxy are hardcoded in
kubeadm-kubelet-config.j2. This commit parameterizes those values and
moves them to main.yml.
2025-07-26 15:02:37 -06:00
Jeff Geerling
2b2efa7f9f Bump to version 1.32. 2025-01-30 22:35:55 -06:00
Jeff Geerling
63ba1cf471 Update CI status badges. 2025-01-30 21:25:15 -06:00
Jeff Geerling
92a5694f6f Don't use sudo inside molecule CI tests. 2025-01-29 21:39:37 -06:00
Jeff Geerling
6baa5d7838
Merge pull request #153 from ndouglas/nd_patch_1
Adopt `deb822_repository` format.
2024-12-13 12:26:45 -06:00
Jeff Geerling
210a0ab262 Fixup CI versions. Drop all older RHEL releases which are broken. 2024-07-16 14:22:27 -05:00
Nathan Douglas
32292cfd89 Just kidding, adding back in the release channel option. 2024-03-06 15:24:35 -05:00
Nathan Douglas
8bfb1d772f Removed some unnecessary stuff. 2024-03-06 13:57:07 -05:00
Nathan Douglas
d4517950a4 Code style. 2024-03-06 06:41:19 -05:00
Nathan Douglas
e35045cc6c FML 2024-03-06 06:40:49 -05:00
Nathan Douglas
904f5be944 Update apt cache when Kubernetes repo is added. 2024-03-06 06:25:22 -05:00
Nathan Douglas
baadacdb3c Add python3-debian to list of dependencies. 2024-03-06 06:15:42 -05:00
Nathan Douglas
038cda429a Revert "Add debian package to be able to use deb822_repository."
This reverts commit 054af0d977.
2024-03-06 06:13:56 -05:00
Nathan Douglas
054af0d977 Add debian package to be able to use deb822_repository. 2024-03-06 06:11:38 -05:00
Nathan Douglas
a8ed657fb3 deb822_repository format 2024-03-06 06:11:38 -05:00
Jeff Geerling
961ed87fca PR #150 follow-up: Update yum package names. 2024-03-05 22:23:18 -06:00
Jeff Geerling
1ac324792d Fix docs for kubernetes apt variables. 2024-03-05 22:11:54 -06:00
Jeff Geerling
9dec31f3a6 Docs updates for previous commit. 2024-03-05 22:09:31 -06:00
Jeff Geerling
2bd76783dd PR #150 follow-up: Update yum repos to new format as well. 2024-03-05 22:09:22 -06:00
Jeff Geerling
928c143c93
Merge pull request #150 from rdxmb/master
update apt sources, add apt keyring gpg
2024-03-05 13:27:30 -06:00
Jeff Geerling
2f9f167dc3 Fixup CI library versions. 2024-01-24 22:11:56 -06:00
Jeff Geerling
d83e2adff2 Make local dev with molecule a little easier. 2024-01-24 21:53:36 -06:00
Marc Bihlmaier
8a50ed5641 remove trailing spaces 2023-11-07 15:22:11 +01:00
Marc Bihlmaier
78169d1895 remove trailing spaces 2023-11-07 15:18:40 +01:00
Marc Bihlmaier
0b73d150af simplify 2023-11-07 15:11:01 +01:00
Marc Bihlmaier
1eb8be8309 update apt sources, add apt keyring gpg 2023-11-07 04:00:59 +01:00
Jeff Geerling
25e782117c Stale bot is now Stale GitHub Action. 2023-07-10 17:48:09 -05:00
Jeff Geerling
aad2912d90 Remove official support for RHEL. Rocky/Alma/Stream support is best-effort. 2023-06-23 10:56:44 -05:00
Jeff Geerling
4271daa2d7 Fix Molecule CI workflow since docker plugin has moved. 2023-06-21 22:21:02 -05:00
Jeff Geerling
82caba3ee1
Merge pull request #148 from speechmatics/fix_networking_retries
add missing 'until' condition in control plane setup
2023-06-21 22:20:54 -05:00
Waldek Maleska
3355986a18
increase networking tasks timeouts 2023-06-21 09:18:21 +01:00
Waldek Maleska
0627acda44
add missing 'until' condition in control plane setup 2023-06-20 17:34:33 +01:00
Jeff Geerling
fc69029f16
Merge pull request #144 from rfranks-securenet/retry-networking-setup
Added retry to networking setup
2023-04-20 17:10:51 -05:00
Richard Franks
270d38ea72 Added retry to networking setup for when the kubelet isn't quite ready yet 2023-04-20 10:54:44 +01:00
Jeff Geerling
4a4c88b6b8 Remove deprecated warn arg from command and shell module invocations. 2022-11-26 22:53:15 -06:00
Jeff Geerling
f8eb97a253 Remove TODOs in code. 2022-10-26 17:26:42 -05:00
Jeff Geerling
86ce85e819
Merge pull request #126 from geerlingguy/fix-ci-updates
Update Kubernetes version and try to get CI passing
2022-10-26 17:25:58 -05:00
Jeff Geerling
040a10d252 Attempt to get tests working with debug. 2022-10-26 12:38:20 -05:00
Jeff Geerling
27837c5671 Use kubelet configuration for swap control and other vars. 2022-10-26 10:34:05 -05:00
Jeff Geerling
219c089243 Debugging with journalctl. 2022-10-26 10:08:27 -05:00
Jeff Geerling
ad1afeebb6 Back to 1.25. 2022-10-26 09:52:57 -05:00
Jeff Geerling
70e203de3f Try Kubernetes 1.24.4. 2022-10-26 09:52:36 -05:00
Jeff Geerling
57292bdfc8 Does it work at all on centos? 2022-10-26 09:52:06 -05:00
Jeff Geerling
d752819b3f See if non-Debian OSes work x2. 2022-10-26 09:52:06 -05:00
Jeff Geerling
39c2a7c4bc See if non-Debian OSes work. 2022-10-26 09:52:06 -05:00
Jeff Geerling
70761e474e Turn off Debian 11 for now. 2022-10-26 09:52:06 -05:00
Jeff Geerling
641beb88bf Disable Calico test right now. 2022-10-26 09:52:06 -05:00
Jeff Geerling
29daceb481 Debugging. 2022-10-26 09:52:06 -05:00
Jeff Geerling
004f583d96 Remove that debug stuff. 2022-10-26 09:52:06 -05:00
Jeff Geerling
724151c5fc Debug. 2022-10-26 09:52:06 -05:00
Jeff Geerling
2fb5b1e993 Attempt to get systemd overlay stuff working correctly. 2022-10-26 09:52:06 -05:00
Jeff Geerling
926a8c909e PR #107: Co-authored commit to change master naming to control plane.
Co-authored-by: ra-rau <mafe2.0@freenet.de>
2022-10-26 09:52:04 -05:00
Jeff Geerling
3a236239a7 Fixes #88: Switch tests and defaults from Docker to containerd. 2022-10-26 09:51:23 -05:00
Jeff Geerling
1881f6161a Fix kubelet and kubeadm configs. 2022-10-26 09:50:50 -05:00
Jeff Geerling
3949ed1e6d Update Kubernetes version to 1.25, see what happens. 2022-10-26 09:50:47 -05:00
Jeff Geerling
a2e8d913e7 Fixes #130: Update path to Flannel manifest file. 2022-10-26 09:49:47 -05:00
Jeff Geerling
6a0573270a Add role_name_check skipping to all molecule test suites. 2022-06-01 22:21:04 -05:00
Jeff Geerling
36ca04d967
Merge pull request #121 from wdennis/wdennis-calico-url-patch
Update Calico manifest URL
2022-04-19 10:20:37 -05:00
Will Dennis
a4dde1bc6b
Update Calico manifest URL
The current Calico manifest URL (https://docs.projectcalico.org/v3.10/manifests/calico.yaml) errors out with various deprecations errors; updating var value to current URL found in Calico install docs (https://projectcalico.docs.tigera.io/getting-started/kubernetes/self-managed-onprem/onpremises) fixes issues in the calling play and runs fine.
2022-04-19 10:28:20 -04:00
Jeff Geerling
925a39a303 Run CI against more modern targets. 2022-04-06 10:46:42 -05:00
Jeff Geerling
e820e27e79 Update release workflow for more consistency. 2021-12-27 11:36:57 -06:00
Jeff Geerling
78940645e9
Merge pull request #111 from ptr-dorjin/fix/typo
docs: fixed a typo in a template name
2021-09-03 10:09:48 -05:00
Peter
d05ab5a7b6 docs: fixed a typo in a template name 2021-09-02 23:43:17 -07:00
Jeff Geerling
c9d6264ad7
Merge pull request #110 from bbcnt/repo_gpg_key_variable
gpgcheck and repo_gpgcheck as vars
2021-08-23 16:17:03 -05:00
Jeff Geerling
ef63ccc0f0 Make sure bugs aren't automatically closed. 2021-08-23 08:53:35 -05:00
Bruno Brito Carvalho
8c3dfc96c3 gpgcheck and repo_gpgcheck as vars 2021-08-23 10:11:06 +02:00
Jeff Geerling
e1199ae5e8 Fixes #72: Remove Web UI / Dashboard setup from role. 2021-08-16 14:55:43 -05:00
Jeff Geerling
cce1780bc3 PR #109: Slight adjustment to wording in README. 2021-08-16 14:52:32 -05:00
Jeff Geerling
7fbb73022a
Merge pull request #109 from ClementGautier/kubeadm-config-improvement
Add way to configure KubeProxy configuration
2021-08-16 14:51:16 -05:00
Clement Gautier
830b35f047
Document kube_proxy_configuration 2021-08-16 11:32:38 +02:00
Clement Gautier
7a40d6f2ae
Add way to configure KubeProxy configuration 2021-08-12 17:03:28 +02:00
Jeff Geerling
64b081472c
Merge pull request #106 from Kedu-SCCL/master
Updated dashboard recommended manifest URL
2021-05-26 09:34:21 -05:00
Kedu SCCL
959eeb4cac
Updated dashboard recommended manifest URL 2021-05-26 11:19:12 +02:00
Jeff Geerling
273fd9ef22
Merge pull request #97 from rdxmb/kubeadm-kubelet-config-file
configure kubeadm and kubelet through config-files
2021-05-07 10:14:34 -05:00
Marc Bihlmaier
47d97ffd07 fix jinja-extension 2021-04-07 20:32:25 +02:00
Marc Bihlmaier
271c4e8a71 fix indents 2021-04-07 20:18:51 +02:00
Marc Bihlmaier
e620266198 add yamllint again 2021-04-07 20:16:45 +02:00
Marc Bihlmaier
c0c36eab5a remove all lint jobs 2021-04-06 17:01:51 +02:00
Marc Bihlmaier
0e124a541f remove lint 2021-04-06 15:54:49 +02:00
Marc Bihlmaier
10eed5fb79 remove yamllint, add ansible-lint 2021-04-06 15:53:00 +02:00
Marc Bihlmaier
be61637a4d configure kubeadm and kubelet through config-files
fix lint

Update README.md

Co-authored-by: Jeff Geerling <geerlingguy@mac.com>

Update defaults/main.yml

Co-authored-by: Jeff Geerling <geerlingguy@mac.com>

Update main.yml
2021-04-06 15:34:42 +02:00
Jeff Geerling
3443efe8db Remove ansible-lint from roles. 2021-03-15 09:28:11 -05:00
Jeff Geerling
6feee1e0c4
Merge pull request #96 from fengye87/master
Change default yum arch to '$basearch'
2021-03-12 09:54:18 -06:00
Feng Ye
a721d30f55
Change default yum arch to '$basearch' 2021-03-12 11:56:10 +08:00
Jeff Geerling
1ccae81a7f Make ansible-lint work again. 2021-02-22 16:30:07 -06:00
Jeff Geerling
9ece16e1c2
Merge pull request #93 from anr09/master
fix the condition to enable Kubernetes Dashboard
2021-01-26 00:06:37 -06:00
An Qiuyu
e4e5c6f3a0
fix the condition to enable Kubernetes Dashboard 2021-01-20 11:02:50 +08:00
Jeff Geerling
41be8a0d07
Merge pull request #87 from fengye87/master
Make YUM baseurl and gpgkey configurable
2020-11-19 12:49:39 -06:00
Feng Ye
a3714d8b79 Make YUM baseurl and gpgkey configurable 2020-11-19 09:33:51 +08:00
Jeff Geerling
2f4fc8f39d Fix CI workflow syntax. 2020-11-05 12:49:32 -06:00
Jeff Geerling
8d36527c6d Dump Travis CI and move to GitHub Actions. 2020-11-05 12:48:22 -06:00
Jeff Geerling
24062aa430 Switch to travis-ci.com. 2020-10-26 20:10:25 -05:00
Jeff Geerling
f5c993eb84 Make sure docker driver is installed with molecule. 2020-10-15 17:04:13 -05:00
Jeff Geerling
690166af9a PR #75 follow-up: Make sure proper package is present and only run on older Debian and other OSes. 2020-09-01 12:22:54 -05:00
Jeff Geerling
749d2869af PR #75 follow-up: Move sysctl setup into separate task file. 2020-09-01 11:30:53 -05:00
Jeff Geerling
c4b512fd26
Merge pull request #75 from jhujasonw/sysctl_bridge_update
Adding settings to sysctl for bridging
2020-09-01 11:29:10 -05:00
Jeff Geerling
0df9c3670a Fixes #82: Update to Kubernetes 1.19 by default. 2020-09-01 11:12:42 -05:00
Jeff Geerling
ce49c9dd82 Ignore the tyranny of ansible-lint rule 106. 2020-08-20 19:21:46 -05:00
Jeff Geerling
2273824910 Fix linting issues. 2020-08-20 12:23:45 -05:00
Jeff Geerling
69db957c4b Upgrade Travis CI docker version to fix Molecule tests. 2020-08-12 14:54:51 -05:00
Jeff Geerling
c27454aefc Ensure galaxy meta information is consistent on all my roles. 2020-05-26 09:45:29 -05:00
Jason Williams
426167cf3b Make sure to quote the values. 2020-05-20 14:05:45 -04:00
Jason Williams
f105b36244 Adding settings to sysctl for briding 2020-05-20 13:57:47 -04:00
Jeff Geerling
8a57427628 Merge branch '73-k8s-version-1-17' 2020-03-23 11:08:12 -05:00
Jeff Geerling
4a9f29670a Issue #73: Bump Kubernetes version to 1.17.2 latest. 2020-03-23 11:01:01 -05:00
Jeff Geerling
07aa887e99 PR #65 follow-up: Clean up formatting slightly. 2020-03-23 10:48:47 -05:00
Jeff Geerling
49217c2f52
Merge pull request #65 from elkouhen/master
Added Weave Network
2020-03-23 10:46:18 -05:00
Jeff Geerling
65b8c76dd7
Merge pull request #36 from rdxmb/fail-when-init-failed
fail when kubeadm init fails
2020-03-18 20:32:13 -05:00
Jeff Geerling
d47b792630
Merge branch 'master' into fail-when-init-failed 2020-03-18 19:44:04 -05:00
Jeff Geerling
9fde307b1e Add probot/stale configuration to repository for stale issues. 2020-03-05 10:43:51 -06:00
Jeff Geerling
dabfb595bd Make sure molecule lint script has set -e option. 2020-02-24 09:44:29 -06:00
Jeff Geerling
514769b9ce Update molecule configuration to work with 3.0. 2020-02-20 15:54:17 -06:00
Jeff Geerling
c4f7e35ce3 Update molecule configuration to work with 3.0. 2020-02-20 14:28:24 -06:00
Jeff Geerling
02d22805e2 Update molecule configuration to work with 3.0. 2020-02-20 14:22:22 -06:00
EL KOUHEN Mehdi
0d0f8e8192
update documentation 2020-01-06 11:00:34 +01:00
EL KOUHEN Mehdi
f149d3b358
Remove option pipefail 2019-12-31 10:01:23 +01:00
EL KOUHEN Mehdi
4b7f0f1e51
Remove Lint Error Comment 2019-12-31 09:48:07 +01:00
Mehdi El Kouhen
c49661ba06 install weave network 2019-12-31 09:24:26 +01:00
Mehdi El Kouhen
b91e92b0b7 install weave network 2019-12-31 09:23:40 +01:00
Jeff Geerling
f912a393b5 Add a test for CentOS 8. 2019-12-17 20:01:47 -06:00
Jeff Geerling
5d8574e871 Fix README formatting. 2019-12-17 17:19:24 -06:00
Jeff Geerling
ae196c82ff PR #53 follow-up: Remove extra unneccessary loop. 2019-12-14 21:31:54 -06:00
Marc Bihlmaier
6d47a11de4 fail when kubeadm init fails 2019-01-02 14:52:15 +01:00
25 changed files with 531 additions and 242 deletions

View File

@ -1,3 +1,4 @@
skip_list:
- '306'
- '405'
- 'yaml'
- 'risky-shell-pipe'
- 'role-name'

74
.github/workflows/ci.yml vendored Normal file
View 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: rockylinux9
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
.github/workflows/release.yml vendored Normal file
View 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
.github/workflows/stale.yml vendored Normal file
View 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 }}

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
*.retry
*/__pycache__
*.pyc
.cache

View File

@ -1,31 +0,0 @@
---
language: python
services: docker
env:
global:
- ROLE_NAME: kubernetes
matrix:
- MOLECULE_DISTRO: centos7
- MOLECULE_DISTRO: ubuntu1804
- MOLECULE_DISTRO: debian10
- MOLECULE_DISTRO: debian10
MOLECULE_PLAYBOOK: playbook-calico.yml
install:
# Install test dependencies.
- pip install molecule docker
before_script:
# Use actual Ansible Galaxy role name for the project directory.
- cd ../
- mv ansible-role-$ROLE_NAME geerlingguy.$ROLE_NAME
- cd geerlingguy.$ROLE_NAME
script:
# Run tests.
- molecule test
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@ -1,6 +1,10 @@
---
extends: default
rules:
line-length:
max: 150
level: warning
ignore: |
.github/workflows/stale.yml

173
README.md
View File

@ -1,90 +1,171 @@
# Ansible Role: Kubernetes
[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-kubernetes.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-kubernetes)
[![CI](https://github.com/geerlingguy/ansible-role-kubernetes/actions/workflows/ci.yml/badge.svg)](https://github.com/geerlingguy/ansible-role-kubernetes/actions/workflows/ci.yml)
An Ansible Role that installs [Kubernetes](https://kubernetes.io) on Linux.
## Requirements
Requires Docker; recommended role for Docker installation: `geerlingguy.docker`.
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`):
kubernetes_packages:
- name: kubelet
state: present
- name: kubectl
state: present
- name: kubeadm
state: present
- name: kubernetes-cni
state: present
```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.
kubernetes_version: '1.16'
kubernetes_version_rhel_package: '1.16.4'
```yaml
kubernetes_version: '1.32'
kubernetes_version_rhel_package: '1.32'
```
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.
kubernetes_role: master
```yaml
kubernetes_role: control_plane
```
Whether the particular server will serve as a Kubernetes `master` (default) or `node`. The master 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 `master`.
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`.
kubernetes_kubelet_extra_args: ""
kubernetes_kubelet_extra_args_config_file: /etc/default/kubelet
### Variables to configure kubeadm and kubelet with `kubeadm init` through a config file (recommended)
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 }}"`.
With this role, `kubeadm init` will be run with `--config <FILE>`.
kubernetes_kubeadm_init_extra_opts: ""
```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"`
kubernetes_join_command_extra_opts: ""
```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`
kubernetes_allow_pods_on_master: true
### Additional variables
Whether to remove the taint that denies pods from being deployed to the Kubernetes master. If you have a single-node cluster, this should definitely be `True`. Otherwise, set to `False` if you want a dedicated Kubernetes master which doesn't run any other pods.
```yaml
kubernetes_allow_pods_on_control_plane: true
```
kubernetes_enable_web_ui: false
kubernetes_web_ui_manifest_file: https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
Whether to enable the Kubernetes web dashboard UI (only accessible on the master itself, or proxied), and the file containing the web dashboard UI manifest.
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) or `calico` for cluster pod networking. Choose one or the other for your cluster; converting between the two is not done automatically and could result in broken networking, and should be done outside of this role.
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.
kubernetes_apiserver_advertise_address: ''
kubernetes_version_kubeadm: 'stable-{{ kubernetes_version }}'
kubernetes_ignore_preflight_errors: 'all'
```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 master. The `kubernetes_apiserver_advertise_address` defaults to `ansible_default_ipv4.address` if it's left empty.
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.
kubernetes_apt_release_channel: main
kubernetes_apt_repository: "deb http://apt.kubernetes.io/ kubernetes-xenial {{ kubernetes_apt_release_channel }}"
kubernetes_apt_ignore_key_error: false
```yaml
kubernetes_apt_release_channel: "stable"
kubernetes_apt_repository: "https://pkgs.k8s.io/core:/{{ kubernetes_apt_release_channel }}:/v{{ kubernetes_version }}/deb/"
```
Apt repository options for Kubernetes installation.
kubernetes_yum_arch: x86_64
```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.
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.
kubernetes_flannel_manifest_file_rbac: https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
kubernetes_flannel_manifest_file: https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
```yaml
kubernetes_flannel_manifest_file: https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
```
Flannel manifest files 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.
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
@ -92,25 +173,25 @@ None.
## Example Playbooks
### Single node (master-only) cluster
### Single node (control-plane-only) cluster
```yaml
- hosts: all
vars:
kubernetes_allow_pods_on_master: true
kubernetes_allow_pods_on_control_plane: true
roles:
- geerlingguy.docker
- geerlingguy.kubernetes
```
### Two or more nodes (single master) cluster
### Two or more nodes (single control-plane) cluster
Master inventory vars:
Control plane inventory vars:
```yaml
kubernetes_role: "master"
kubernetes_role: "control_plane"
```
Node(s) inventory vars:
@ -125,14 +206,14 @@ Playbook:
- hosts: all
vars:
kubernetes_allow_pods_on_master: true
kubernetes_allow_pods_on_control_plane: true
roles:
- geerlingguy.docker
- geerlingguy.kubernetes
```
Then, log into the Kubernetes master, and run `kubectl get nodes` as root, and you should see a list of all the servers.
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

View File

@ -9,19 +9,17 @@ kubernetes_packages:
- name: kubernetes-cni
state: present
kubernetes_version: '1.16'
kubernetes_version_rhel_package: '1.16.4'
kubernetes_version: '1.32'
kubernetes_version_rhel_package: '1.32'
kubernetes_role: master
kubernetes_role: control_plane
# 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_master: true
kubernetes_enable_web_ui: true
kubernetes_web_ui_manifest_file: https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
kubernetes_allow_pods_on_control_plane: true
kubernetes_pod_network:
# Flannel CNI.
cni: 'flannel'
@ -30,20 +28,44 @@ kubernetes_pod_network:
# cni: 'calico'
# cidr: '192.168.0.0/16'
kubernetes_kubeadm_kubelet_config_file_path: '/etc/kubernetes/kubeadm-kubelet-config.yaml'
kubernetes_config_kubeadm_apiversion: v1beta3
kubenetes_config_kubelet_apiversion: v1beta1
kubernetes_config_kubeproxy_apiversion: v1alpha1
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: main
# Note that xenial repo is used for all Debian derivatives at this time.
kubernetes_apt_repository: "deb http://apt.kubernetes.io/ kubernetes-xenial {{ kubernetes_apt_release_channel }}"
kubernetes_apt_ignore_key_error: false
kubernetes_apt_release_channel: "stable"
kubernetes_apt_repository: "https://pkgs.k8s.io/core:/{{ kubernetes_apt_release_channel }}:/v{{ kubernetes_version }}/deb/"
kubernetes_yum_arch: x86_64
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 files.
kubernetes_flannel_manifest_file_rbac: https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
kubernetes_flannel_manifest_file: https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# Flannel config file.
kubernetes_flannel_manifest_file: https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
# Calico config files
kubernetes_calico_manifest_file: https://docs.projectcalico.org/v3.10/manifests/calico.yaml
# Calico config file.
kubernetes_calico_manifest_file: https://projectcalico.docs.tigera.io/manifests/calico.yaml

View File

@ -2,24 +2,24 @@
dependencies: []
galaxy_info:
role_name: kubernetes
author: geerlingguy
description: Kubernetes for Linux.
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 2.4
min_ansible_version: 2.10
platforms:
- name: EL
versions:
- 7
- 8
- name: Debian
versions:
- stretch
- buster
- bullseye
- name: Ubuntu
versions:
- xenial
- bionic
- focal
- jammy
galaxy_tags:
- system
- containers

View File

@ -1,16 +1,20 @@
---
- name: Converge
hosts: all
become: true
#become: true
vars:
kubernetes_pod_network:
cni: 'calico'
cidr: '192.168.0.0/16'
# Allow swap in test environments (hard to control in some Docker envs).
kubernetes_kubelet_extra_args: "--fail-swap-on=false --cgroup-driver=cgroupfs"
docker_install_compose: false
# 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.
@ -29,7 +33,7 @@
action: setup
roles:
- role: geerlingguy.docker
- role: geerlingguy.containerd
- role: geerlingguy.kubernetes
post_tasks:

View File

@ -1,12 +1,16 @@
---
- name: Converge
hosts: all
become: true
#become: true
vars:
# Allow swap in test environments (hard to control in some Docker envs).
kubernetes_kubelet_extra_args: "--fail-swap-on=false --cgroup-driver=cgroupfs"
docker_install_compose: false
# 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.
@ -25,7 +29,7 @@
action: setup
roles:
- role: geerlingguy.docker
- role: geerlingguy.containerd
- role: geerlingguy.kubernetes
post_tasks:

View File

@ -1,30 +1,22 @@
---
role_name_check: 1
dependency:
name: galaxy
options:
ignore-errors: true
driver:
name: docker
lint:
name: yamllint
options:
config-file: molecule/default/yaml-lint.yml
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux9}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- /var/lib/docker
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- /var/lib/containerd
cgroupns_mode: host
privileged: true
pre_build_image: true
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
converge: ${MOLECULE_PLAYBOOK:-converge.yml}

View File

@ -1,2 +1,2 @@
---
- src: geerlingguy.docker
- src: geerlingguy.containerd

View 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

View File

@ -1,34 +1,42 @@
---
- name: Check for existence of kubelet environment file.
# ---- 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.
- 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.
- 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.
- name: Configure KUBELET_EXTRA_ARGS. (deprecated)
lineinfile:
path: '{{ kubelet_args_path }}'
line: '{{ kubelet_args_line }}'
regexp: '{{ kubelet_args_regexp }}'
state: present
register: kubelet_config_file
mode: 0644
register: kubelet_extra_args
when: kubernetes_kubelet_extra_args|length > 0
- name: Reload systemd unit if args were changed.
- name: Reload systemd unit if args were changed. (deprecated)
systemd:
state: restarted
daemon_reload: true
name: kubelet
when: kubelet_config_file is changed
when: kubelet_extra_args is changed

View File

@ -18,7 +18,10 @@
notify: restart kubelet
with_items: "{{ kubernetes_packages }}"
- include_tasks: kubelet-setup.yml
- 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:
@ -31,15 +34,15 @@
path: /etc/kubernetes/admin.conf
register: kubernetes_init_stat
# Set up master.
- include_tasks: master-setup.yml
when: kubernetes_role == 'master'
# 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 master.
- name: Get the kubeadm join command from the Kubernetes control plane.
command: kubeadm token create --print-join-command
changed_when: false
when: kubernetes_role == 'master'
when: kubernetes_role == 'control_plane'
register: kubernetes_join_command_result
- name: Set the kubeadm join command globally.

View File

@ -1,68 +0,0 @@
---
- name: Initialize Kubernetes master with kubeadm init.
command: >
kubeadm init
--pod-network-cidr={{ kubernetes_pod_network.cidr }}
--apiserver-advertise-address={{ kubernetes_apiserver_advertise_address | default(ansible_default_ipv4.address, true) }}
--kubernetes-version {{ kubernetes_version_kubeadm }}
--ignore-preflight-errors={{ kubernetes_ignore_preflight_errors }}
{{ kubernetes_kubeadm_init_extra_opts }}
with_items: "{{ kubernetes_pod_network }}"
register: kubeadmin_init
failed_when: false
when: not kubernetes_init_stat.stat.exists
- 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
- name: Symlink the kubectl admin.conf to ~/.kube/conf.
file:
src: /etc/kubernetes/admin.conf
dest: ~/.kube/config
state: link
- name: Configure Flannel networking.
command: "{{ item }}"
with_items:
- kubectl apply -f {{ kubernetes_flannel_manifest_file_rbac }}
- kubectl apply -f {{ kubernetes_flannel_manifest_file }}
register: flannel_result
changed_when: "'created' in flannel_result.stdout"
when: kubernetes_pod_network.cni == 'flannel'
- name: Configure Calico networking.
command: "{{ item }}"
with_items:
- kubectl apply -f {{ kubernetes_calico_manifest_file }}
register: calico_result
changed_when: "'created' in calico_result.stdout"
when: kubernetes_pod_network.cni == 'calico'
# TODO: Check if taint exists with something like `kubectl describe nodes`
# instead of using kubernetes_init_stat.stat.exists check.
- name: Allow pods on master node (if configured).
command: "kubectl taint nodes --all node-role.kubernetes.io/master-"
when:
- kubernetes_allow_pods_on_master | bool
- not kubernetes_init_stat.stat.exists
- name: Check if Kubernetes Dashboard UI service already exists.
shell: kubectl get services --namespace kube-system | grep -q kubernetes-dashboard
changed_when: false
failed_when: false
register: kubernetes_dashboard_service
when: kubernetes_enable_web_ui | bool
- name: Enable the Kubernetes Web Dashboard UI (if configured).
command: "kubectl create -f {{ kubernetes_web_ui_manifest_file }}"
when:
- kubernetes_enable_web_ui | bool
- kubernetes_dashboard_service is failed

View File

@ -1,5 +1,5 @@
---
- name: Join node to Kubernetes master
- name: Join node to Kubernetes control plane.
shell: >
{{ kubernetes_join_command }}
creates=/etc/kubernetes/kubelet.conf

View File

@ -4,22 +4,25 @@
name:
- apt-transport-https
- ca-certificates
- python3-debian
state: present
- name: Add Kubernetes apt key.
apt_key:
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
state: present
register: add_repository_key
ignore_errors: "{{ kubernetes_apt_ignore_key_error }}"
- name: Add Kubernetes repository.
apt_repository:
repo: "{{ kubernetes_apt_repository }}"
state: present
deb822_repository:
name: kubernetes
types: deb
uris: "{{ kubernetes_apt_repository }}"
suites: /
signed_by: "{{ kubernetes_apt_repository }}/Release.key"
register: kubernetes_repository
- name: Update Apt cache.
apt:
update_cache: true
when: kubernetes_repository.changed
- name: Add Kubernetes apt preferences file to pin a version.
template:
src: apt-preferences-kubernetes.j2
dest: /etc/apt/preferences.d/kubernetes
mode: 0644

View File

@ -4,24 +4,17 @@
name: kubernetes
description: Kubernetes
enabled: true
gpgcheck: true
repo_gpgcheck: true
baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-{{ kubernetes_yum_arch }}
gpgkey:
- https://packages.cloud.google.com/yum/doc/yum-key.gpg
- https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
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: "{{ item }}"
key: "{{ kubernetes_yum_gpg_key }}"
state: present
register: kubernetes_rpm_key
with_items:
- https://packages.cloud.google.com/yum/doc/yum-key.gpg
- https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
- name: Make cache if Kubernetes GPG key changed.
command: "yum -q makecache -y --disablerepo='*' --enablerepo='kubernetes'"
when: kubernetes_rpm_key is changed
args:
warn: false

21
tasks/sysctl-setup.yml Normal file
View 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

View File

@ -0,0 +1,20 @@
---
apiVersion: kubeadm.k8s.io/{{ kubernetes_config_kubeadm_apiversion }}
kind: InitConfiguration
{{ kubernetes_config_init_configuration | to_nice_yaml }}
---
apiVersion: kubeadm.k8s.io/{{ kubernetes_config_kubeadm_apiversion }}
kind: ClusterConfiguration
{{ kubernetes_config_cluster_configuration | to_nice_yaml }}
{% if kubernetes_config_kubelet_configuration|length > 0 %}
---
apiVersion: kubelet.config.k8s.io/{{ kubenetes_config_kubelet_apiversion }}
kind: KubeletConfiguration
{{ kubernetes_config_kubelet_configuration | to_nice_yaml }}
{% endif %}
{% if kubernetes_config_kube_proxy_configuration|length > 0 %}
---
apiVersion: kubeproxy.config.k8s.io/{{ kubernetes_config_kubeproxy_apiversion }}
kind: KubeProxyConfiguration
{{ kubernetes_config_kube_proxy_configuration | to_nice_yaml }}
{% endif %}

View File

@ -1,2 +1,3 @@
---
procps_package: procps
kubelet_environment_file_path: /etc/default/kubelet

View File

@ -1,11 +1,3 @@
---
procps_package: procps-ng
kubelet_environment_file_path: /etc/sysconfig/kubelet
kubernetes_packages:
- name: kubelet-{{ kubernetes_version_rhel_package }}-0
state: present
- name: kubectl-{{ kubernetes_version_rhel_package }}-0
state: present
- name: kubeadm-{{ kubernetes_version_rhel_package }}-0
state: present
- name: kubernetes-cni
state: present