Add a little test bed for k8s
IT WORKS
This commit is contained in:
parent
dc687da6c1
commit
2773f537bc
@ -27,3 +27,33 @@ all:
|
|||||||
game:
|
game:
|
||||||
hosts:
|
hosts:
|
||||||
game1.desu.ltd:
|
game1.desu.ltd:
|
||||||
|
k8s:
|
||||||
|
vars:
|
||||||
|
ansible_become: yes
|
||||||
|
children:
|
||||||
|
k8s_masters:
|
||||||
|
vars:
|
||||||
|
kubernetes_role: master
|
||||||
|
hosts:
|
||||||
|
kub-ms1:
|
||||||
|
ansible_host: 192.168.122.82
|
||||||
|
k8s_nodes:
|
||||||
|
vars:
|
||||||
|
kubernetes_role: node
|
||||||
|
hosts:
|
||||||
|
kub-node1:
|
||||||
|
ansible_host: 192.168.122.120
|
||||||
|
kub-node2:
|
||||||
|
ansible_host: 192.168.122.151
|
||||||
|
kub-node3:
|
||||||
|
ansible_host: 192.168.122.131
|
||||||
|
kub-node4:
|
||||||
|
ansible_host: 192.168.122.234
|
||||||
|
kub-node5:
|
||||||
|
ansible_host: 192.168.122.109
|
||||||
|
kub-node6:
|
||||||
|
ansible_host: 192.168.122.105
|
||||||
|
kub-node7:
|
||||||
|
ansible_host: 192.168.122.157
|
||||||
|
kub-node8:
|
||||||
|
ansible_host: 192.168.122.221
|
||||||
|
15
playbooks/k8s.yml
Executable file
15
playbooks/k8s.yml
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env ansible-playbook
|
||||||
|
# vim:ft=ansible:
|
||||||
|
# My personal k8s cluster
|
||||||
|
---
|
||||||
|
- hosts: k8s
|
||||||
|
roles:
|
||||||
|
- role: docker
|
||||||
|
tags: [ k8s, docker ]
|
||||||
|
# Note: the master and all its nodes must run this role at the same time
|
||||||
|
# in order for the join token to be registered properly.
|
||||||
|
# Failure to do so will result in nodes not joining the cluster.
|
||||||
|
- role: k8s
|
||||||
|
vars:
|
||||||
|
kubernetes_enable_web_ui: yes
|
||||||
|
tags: [ k8s ]
|
3
roles/docker/.ansible-lint
Normal file
3
roles/docker/.ansible-lint
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
skip_list:
|
||||||
|
- '306'
|
||||||
|
- '106'
|
4
roles/docker/.github/FUNDING.yml
vendored
Normal file
4
roles/docker/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
---
|
||||||
|
github: geerlingguy
|
||||||
|
patreon: geerlingguy
|
56
roles/docker/.github/stale.yml
vendored
Normal file
56
roles/docker/.github/stale.yml
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
# 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:
|
||||||
|
- 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.
|
72
roles/docker/.github/workflows/ci.yml
vendored
Normal file
72
roles/docker/.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
---
|
||||||
|
name: CI
|
||||||
|
'on':
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
schedule:
|
||||||
|
- cron: "0 7 * * 0"
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: 'geerlingguy.docker'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out the codebase.
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.docker'
|
||||||
|
|
||||||
|
- name: Set up Python 3.
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install test dependencies.
|
||||||
|
run: pip3 install yamllint ansible-lint
|
||||||
|
|
||||||
|
- name: Lint code.
|
||||||
|
run: |
|
||||||
|
yamllint .
|
||||||
|
ansible-lint
|
||||||
|
|
||||||
|
molecule:
|
||||||
|
name: Molecule
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
distro:
|
||||||
|
- centos8
|
||||||
|
- centos7
|
||||||
|
- ubuntu2004
|
||||||
|
- ubuntu1804
|
||||||
|
- debian10
|
||||||
|
- debian9
|
||||||
|
- fedora31
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out the codebase.
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.docker'
|
||||||
|
|
||||||
|
- 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 }}
|
38
roles/docker/.github/workflows/release.yml
vendored
Normal file
38
roles/docker/.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
# 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.docker'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
release:
|
||||||
|
name: Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out the codebase.
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.docker'
|
||||||
|
|
||||||
|
- name: Set up Python 3.
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install Ansible.
|
||||||
|
run: pip3 install ansible-base
|
||||||
|
|
||||||
|
- 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)
|
3
roles/docker/.gitignore
vendored
Normal file
3
roles/docker/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*.retry
|
||||||
|
*/__pycache__
|
||||||
|
*.pyc
|
11
roles/docker/.yamllint
Normal file
11
roles/docker/.yamllint
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 200
|
||||||
|
level: warning
|
||||||
|
|
||||||
|
ignore: |
|
||||||
|
.github/stale.yml
|
||||||
|
.travis.yml
|
20
roles/docker/LICENSE
Normal file
20
roles/docker/LICENSE
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2017 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.
|
97
roles/docker/README.md
Normal file
97
roles/docker/README.md
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
# Ansible Role: Docker
|
||||||
|
|
||||||
|
[![CI](https://github.com/geerlingguy/ansible-role-docker/workflows/CI/badge.svg?event=push)](https://github.com/geerlingguy/ansible-role-docker/actions?query=workflow%3ACI)
|
||||||
|
|
||||||
|
An Ansible Role that installs [Docker](https://www.docker.com) on Linux.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
## Role Variables
|
||||||
|
|
||||||
|
Available variables are listed below, along with default values (see `defaults/main.yml`):
|
||||||
|
|
||||||
|
# Edition can be one of: 'ce' (Community Edition) or 'ee' (Enterprise Edition).
|
||||||
|
docker_edition: 'ce'
|
||||||
|
docker_package: "docker-{{ docker_edition }}"
|
||||||
|
docker_package_state: present
|
||||||
|
|
||||||
|
The `docker_edition` should be either `ce` (Community Edition) or `ee` (Enterprise Edition). You can also specify a specific version of Docker to install using the distribution-specific format: Red Hat/CentOS: `docker-{{ docker_edition }}-<VERSION>`; Debian/Ubuntu: `docker-{{ docker_edition }}=<VERSION>`.
|
||||||
|
|
||||||
|
You can control whether the package is installed, uninstalled, or at the latest version by setting `docker_package_state` to `present`, `absent`, or `latest`, respectively. Note that the Docker daemon will be automatically restarted if the Docker package is updated. This is a side effect of flushing all handlers (running any of the handlers that have been notified by this and any other role up to this point in the play).
|
||||||
|
|
||||||
|
docker_service_state: started
|
||||||
|
docker_service_enabled: true
|
||||||
|
docker_restart_handler_state: restarted
|
||||||
|
|
||||||
|
Variables to control the state of the `docker` service, and whether it should start on boot. If you're installing Docker inside a Docker container without systemd or sysvinit, you should set these to `stopped` and set the enabled variable to `no`.
|
||||||
|
|
||||||
|
docker_install_compose: true
|
||||||
|
docker_compose_version: "1.26.0"
|
||||||
|
docker_compose_path: /usr/local/bin/docker-compose
|
||||||
|
|
||||||
|
Docker Compose installation options.
|
||||||
|
|
||||||
|
docker_apt_release_channel: stable
|
||||||
|
docker_apt_arch: 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 Debian/Ubuntu.) You can switch the channel to `nightly` if you want to use the Nightly release.
|
||||||
|
|
||||||
|
You can change `docker_apt_gpg_key` to a different url if you are behind a firewall or provide a trustworthy mirror.
|
||||||
|
Usually in combination with changing `docker_apt_repository` as well.
|
||||||
|
|
||||||
|
docker_yum_repo_url: https://download.docker.com/linux/centos/docker-{{ docker_edition }}.repo
|
||||||
|
docker_yum_repo_enable_nightly: '0'
|
||||||
|
docker_yum_repo_enable_test: '0'
|
||||||
|
docker_yum_gpg_key: https://download.docker.com/linux/centos/gpg
|
||||||
|
|
||||||
|
(Used only for RedHat/CentOS.) You can enable the Nightly or Test repo by setting the respective vars to `1`.
|
||||||
|
|
||||||
|
You can change `docker_yum_gpg_key` to a different url if you are behind a firewall or provide a trustworthy mirror.
|
||||||
|
Usually in combination with changing `docker_yum_repository` as well.
|
||||||
|
|
||||||
|
docker_users:
|
||||||
|
- user1
|
||||||
|
- user2
|
||||||
|
|
||||||
|
A list of system users to be added to the `docker` group (so they can use Docker on the server).
|
||||||
|
|
||||||
|
## Use with Ansible (and `docker` Python library)
|
||||||
|
|
||||||
|
Many users of this role wish to also use Ansible to then _build_ Docker images and manage Docker containers on the server where Docker is installed. In this case, you can easily add in the `docker` Python library using the `geerlingguy.pip` role:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- hosts: all
|
||||||
|
|
||||||
|
vars:
|
||||||
|
pip_install_packages:
|
||||||
|
- name: docker
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- geerlingguy.pip
|
||||||
|
- geerlingguy.docker
|
||||||
|
```
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
## Example Playbook
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- hosts: all
|
||||||
|
roles:
|
||||||
|
- geerlingguy.docker
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT / BSD
|
||||||
|
|
||||||
|
## Author Information
|
||||||
|
|
||||||
|
This role was created in 2017 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
|
31
roles/docker/defaults/main.yml
Normal file
31
roles/docker/defaults/main.yml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
# Edition can be one of: 'ce' (Community Edition) or 'ee' (Enterprise Edition).
|
||||||
|
docker_edition: 'ce'
|
||||||
|
docker_package: "docker-{{ docker_edition }}"
|
||||||
|
docker_package_state: present
|
||||||
|
|
||||||
|
# Service options.
|
||||||
|
docker_service_state: started
|
||||||
|
docker_service_enabled: true
|
||||||
|
docker_restart_handler_state: restarted
|
||||||
|
|
||||||
|
# Docker Compose options.
|
||||||
|
docker_install_compose: true
|
||||||
|
docker_compose_version: "1.26.0"
|
||||||
|
docker_compose_path: /usr/local/bin/docker-compose
|
||||||
|
|
||||||
|
# Used only for Debian/Ubuntu. Switch 'stable' to 'nightly' if needed.
|
||||||
|
docker_apt_release_channel: stable
|
||||||
|
docker_apt_arch: 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-{{ docker_edition }}.repo
|
||||||
|
docker_yum_repo_enable_nightly: '0'
|
||||||
|
docker_yum_repo_enable_test: '0'
|
||||||
|
docker_yum_gpg_key: https://download.docker.com/linux/centos/gpg
|
||||||
|
|
||||||
|
# A list of users who will be added to the docker group.
|
||||||
|
docker_users: []
|
3
roles/docker/handlers/main.yml
Normal file
3
roles/docker/handlers/main.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
- name: restart docker
|
||||||
|
service: "name=docker state={{ docker_restart_handler_state }}"
|
2
roles/docker/meta/.galaxy_install_info
Normal file
2
roles/docker/meta/.galaxy_install_info
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
install_date: Tue Feb 16 21:35:59 2021
|
||||||
|
version: 3.0.0
|
35
roles/docker/meta/main.yml
Normal file
35
roles/docker/meta/main.yml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
---
|
||||||
|
dependencies: []
|
||||||
|
|
||||||
|
galaxy_info:
|
||||||
|
role_name: docker
|
||||||
|
author: geerlingguy
|
||||||
|
description: Docker for Linux.
|
||||||
|
company: "Midwestern Mac, LLC"
|
||||||
|
license: "license (BSD, MIT)"
|
||||||
|
min_ansible_version: 2.4
|
||||||
|
platforms:
|
||||||
|
- name: EL
|
||||||
|
versions:
|
||||||
|
- 7
|
||||||
|
- 8
|
||||||
|
- name: Fedora
|
||||||
|
versions:
|
||||||
|
- all
|
||||||
|
- name: Debian
|
||||||
|
versions:
|
||||||
|
- stretch
|
||||||
|
- buster
|
||||||
|
- name: Ubuntu
|
||||||
|
versions:
|
||||||
|
- xenial
|
||||||
|
- bionic
|
||||||
|
- focal
|
||||||
|
galaxy_tags:
|
||||||
|
- web
|
||||||
|
- system
|
||||||
|
- containers
|
||||||
|
- docker
|
||||||
|
- orchestration
|
||||||
|
- compose
|
||||||
|
- server
|
24
roles/docker/molecule/default/converge.yml
Normal file
24
roles/docker/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.docker
|
17
roles/docker/molecule/default/molecule.yml
Normal file
17
roles/docker/molecule/default/molecule.yml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
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}
|
20
roles/docker/tasks/docker-compose.yml
Normal file
20
roles/docker/tasks/docker-compose.yml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
- name: Check current docker-compose version.
|
||||||
|
command: docker-compose --version
|
||||||
|
register: docker_compose_current_version
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Delete existing docker-compose version if it's different.
|
||||||
|
file:
|
||||||
|
path: "{{ docker_compose_path }}"
|
||||||
|
state: absent
|
||||||
|
when: >
|
||||||
|
docker_compose_current_version.stdout is defined
|
||||||
|
and docker_compose_version not in docker_compose_current_version.stdout
|
||||||
|
|
||||||
|
- name: Install Docker Compose (if configured).
|
||||||
|
get_url:
|
||||||
|
url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64
|
||||||
|
dest: "{{ docker_compose_path }}"
|
||||||
|
mode: 0755
|
7
roles/docker/tasks/docker-users.yml
Normal file
7
roles/docker/tasks/docker-users.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure docker users are added to the docker group.
|
||||||
|
user:
|
||||||
|
name: "{{ item }}"
|
||||||
|
groups: docker
|
||||||
|
append: true
|
||||||
|
with_items: "{{ docker_users }}"
|
27
roles/docker/tasks/main.yml
Normal file
27
roles/docker/tasks/main.yml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
- include_tasks: setup-RedHat.yml
|
||||||
|
when: ansible_os_family == 'RedHat'
|
||||||
|
|
||||||
|
- include_tasks: setup-Debian.yml
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- name: Install Docker.
|
||||||
|
package:
|
||||||
|
name: "{{ docker_package }}"
|
||||||
|
state: "{{ docker_package_state }}"
|
||||||
|
notify: restart docker
|
||||||
|
|
||||||
|
- name: Ensure Docker is started and enabled at boot.
|
||||||
|
service:
|
||||||
|
name: docker
|
||||||
|
state: "{{ docker_service_state }}"
|
||||||
|
enabled: "{{ docker_service_enabled }}"
|
||||||
|
|
||||||
|
- name: Ensure handlers are notified now to avoid firewall conflicts.
|
||||||
|
meta: flush_handlers
|
||||||
|
|
||||||
|
- include_tasks: docker-compose.yml
|
||||||
|
when: docker_install_compose | bool
|
||||||
|
|
||||||
|
- include_tasks: docker-users.yml
|
||||||
|
when: docker_users | length > 0
|
40
roles/docker/tasks/setup-Debian.yml
Normal file
40
roles/docker/tasks/setup-Debian.yml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure old versions of Docker are not installed.
|
||||||
|
package:
|
||||||
|
name:
|
||||||
|
- docker
|
||||||
|
- docker-engine
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- 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 -
|
||||||
|
args:
|
||||||
|
warn: false
|
||||||
|
when: add_repository_key is failed
|
||||||
|
|
||||||
|
- name: Add Docker repository.
|
||||||
|
apt_repository:
|
||||||
|
repo: "{{ docker_apt_repository }}"
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
50
roles/docker/tasks/setup-RedHat.yml
Normal file
50
roles/docker/tasks/setup-RedHat.yml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure old versions of Docker are not installed.
|
||||||
|
package:
|
||||||
|
name:
|
||||||
|
- docker
|
||||||
|
- docker-common
|
||||||
|
- docker-engine
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- 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-{{ docker_edition }}.repo'
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
|
|
||||||
|
- name: Configure Docker Nightly repo.
|
||||||
|
ini_file:
|
||||||
|
dest: '/etc/yum.repos.d/docker-{{ docker_edition }}.repo'
|
||||||
|
section: 'docker-{{ docker_edition }}-nightly'
|
||||||
|
option: enabled
|
||||||
|
value: '{{ docker_yum_repo_enable_nightly }}'
|
||||||
|
mode: 0644
|
||||||
|
|
||||||
|
- name: Configure Docker Test repo.
|
||||||
|
ini_file:
|
||||||
|
dest: '/etc/yum.repos.d/docker-{{ docker_edition }}.repo'
|
||||||
|
section: 'docker-{{ docker_edition }}-test'
|
||||||
|
option: enabled
|
||||||
|
value: '{{ docker_yum_repo_enable_test }}'
|
||||||
|
mode: 0644
|
||||||
|
|
||||||
|
- name: Configure containerd on RHEL 8.
|
||||||
|
block:
|
||||||
|
- name: Ensure container-selinux is installed.
|
||||||
|
package:
|
||||||
|
name: container-selinux
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Ensure containerd.io is installed.
|
||||||
|
package:
|
||||||
|
name: containerd.io
|
||||||
|
state: present
|
||||||
|
when: ansible_distribution_major_version | int == 8
|
4
roles/k8s/.ansible-lint
Normal file
4
roles/k8s/.ansible-lint
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
skip_list:
|
||||||
|
- '306'
|
||||||
|
- '405'
|
||||||
|
- '106'
|
4
roles/k8s/.github/FUNDING.yml
vendored
Normal file
4
roles/k8s/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
---
|
||||||
|
github: geerlingguy
|
||||||
|
patreon: geerlingguy
|
56
roles/k8s/.github/stale.yml
vendored
Normal file
56
roles/k8s/.github/stale.yml
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
# 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:
|
||||||
|
- 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.
|
77
roles/k8s/.github/workflows/ci.yml
vendored
Normal file
77
roles/k8s/.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
---
|
||||||
|
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@v2
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.kubernetes'
|
||||||
|
|
||||||
|
- name: Set up Python 3.
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install test dependencies.
|
||||||
|
run: pip3 install yamllint ansible-lint
|
||||||
|
|
||||||
|
- name: Lint code.
|
||||||
|
run: |
|
||||||
|
yamllint .
|
||||||
|
ansible-lint
|
||||||
|
|
||||||
|
molecule:
|
||||||
|
name: Molecule
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- distro: centos8
|
||||||
|
playbook: converge.yml
|
||||||
|
- distro: centos7
|
||||||
|
playbook: converge.yml
|
||||||
|
- distro: ubuntu1804
|
||||||
|
playbook: converge.yml
|
||||||
|
- distro: debian10
|
||||||
|
playbook: converge.yml
|
||||||
|
|
||||||
|
- distro: debian10
|
||||||
|
playbook: calico.yml
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out the codebase.
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.kubernetes'
|
||||||
|
|
||||||
|
- 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 }}
|
||||||
|
MOLECULE_PLAYBOOK: ${{ matrix.playbook }}
|
38
roles/k8s/.github/workflows/release.yml
vendored
Normal file
38
roles/k8s/.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
# 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@v2
|
||||||
|
with:
|
||||||
|
path: 'geerlingguy.kubernetes'
|
||||||
|
|
||||||
|
- name: Set up Python 3.
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install Ansible.
|
||||||
|
run: pip3 install ansible-base
|
||||||
|
|
||||||
|
- 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)
|
3
roles/k8s/.gitignore
vendored
Normal file
3
roles/k8s/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*.retry
|
||||||
|
*/__pycache__
|
||||||
|
*.pyc
|
36
roles/k8s/.travis.yml
Normal file
36
roles/k8s/.travis.yml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
---
|
||||||
|
language: python
|
||||||
|
services: docker
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- ROLE_NAME: kubernetes
|
||||||
|
matrix:
|
||||||
|
- MOLECULE_DISTRO: centos8
|
||||||
|
- MOLECULE_DISTRO: centos7
|
||||||
|
- MOLECULE_DISTRO: ubuntu1804
|
||||||
|
- MOLECULE_DISTRO: debian10
|
||||||
|
|
||||||
|
- MOLECULE_DISTRO: debian10
|
||||||
|
MOLECULE_PLAYBOOK: playbook-calico.yml
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
# Upgrade Docker to work with docker-py.
|
||||||
|
- curl https://gist.githubusercontent.com/geerlingguy/ce883ad4aec6a5f1187ef93bd338511e/raw/36612d28981d92863f839c5aefe5b7dd7193d6c6/travis-ci-docker-upgrade.sh | sudo bash
|
||||||
|
|
||||||
|
install:
|
||||||
|
# Install test dependencies.
|
||||||
|
- pip install molecule[docker] yamllint ansible-lint 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/
|
11
roles/k8s/.yamllint
Normal file
11
roles/k8s/.yamllint
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 150
|
||||||
|
level: warning
|
||||||
|
|
||||||
|
ignore: |
|
||||||
|
.github/stale.yml
|
||||||
|
.travis.yml
|
20
roles/k8s/LICENSE
Normal file
20
roles/k8s/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.
|
152
roles/k8s/README.md
Normal file
152
roles/k8s/README.md
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
# Ansible Role: Kubernetes
|
||||||
|
|
||||||
|
[![CI](https://github.com/geerlingguy/ansible-role-kubernetes/workflows/CI/badge.svg?event=push)](https://github.com/geerlingguy/ansible-role-kubernetes/actions?query=workflow%3ACI)
|
||||||
|
|
||||||
|
An Ansible Role that installs [Kubernetes](https://kubernetes.io) on Linux.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
Requires Docker; recommended role for Docker installation: `geerlingguy.docker`.
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
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.17'
|
||||||
|
kubernetes_version_rhel_package: '1.17.2'
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|
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 }}"`.
|
||||||
|
|
||||||
|
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: ""
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
Apt repository options for Kubernetes installation.
|
||||||
|
|
||||||
|
kubernetes_yum_arch: x86_64
|
||||||
|
kubernetes_yum_base_url: "https://packages.cloud.google.com/yum/repos/kubernetes-el7-{{ kubernetes_yum_arch }}"
|
||||||
|
kubernetes_yum_gpg_key:
|
||||||
|
- https://packages.cloud.google.com/yum/doc/yum-key.gpg
|
||||||
|
- https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
## Example Playbooks
|
||||||
|
|
||||||
|
### Single node (master-only) cluster
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- hosts: all
|
||||||
|
|
||||||
|
vars:
|
||||||
|
kubernetes_allow_pods_on_master: true
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- geerlingguy.docker
|
||||||
|
- geerlingguy.kubernetes
|
||||||
|
```
|
||||||
|
|
||||||
|
### Two or more nodes (single master) cluster
|
||||||
|
|
||||||
|
Master inventory vars:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_role: "master"
|
||||||
|
```
|
||||||
|
|
||||||
|
Node(s) inventory vars:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kubernetes_role: "node"
|
||||||
|
```
|
||||||
|
|
||||||
|
Playbook:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- hosts: all
|
||||||
|
|
||||||
|
vars:
|
||||||
|
kubernetes_allow_pods_on_master: 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.
|
||||||
|
|
||||||
|
## 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/).
|
53
roles/k8s/defaults/main.yml
Normal file
53
roles/k8s/defaults/main.yml
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
---
|
||||||
|
kubernetes_packages:
|
||||||
|
- name: kubelet
|
||||||
|
state: present
|
||||||
|
- name: kubectl
|
||||||
|
state: present
|
||||||
|
- name: kubeadm
|
||||||
|
state: present
|
||||||
|
- name: kubernetes-cni
|
||||||
|
state: present
|
||||||
|
|
||||||
|
kubernetes_version: '1.19'
|
||||||
|
kubernetes_version_rhel_package: '1.19.0'
|
||||||
|
|
||||||
|
kubernetes_role: master
|
||||||
|
|
||||||
|
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_pod_network:
|
||||||
|
# Flannel CNI.
|
||||||
|
cni: 'flannel'
|
||||||
|
cidr: '10.244.0.0/16'
|
||||||
|
# Calico CNI.
|
||||||
|
# cni: 'calico'
|
||||||
|
# cidr: '192.168.0.0/16'
|
||||||
|
|
||||||
|
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_yum_arch: x86_64
|
||||||
|
kubernetes_yum_base_url: "https://packages.cloud.google.com/yum/repos/kubernetes-el7-{{ kubernetes_yum_arch }}"
|
||||||
|
kubernetes_yum_gpg_key:
|
||||||
|
- https://packages.cloud.google.com/yum/doc/yum-key.gpg
|
||||||
|
- https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Calico config files
|
||||||
|
kubernetes_calico_manifest_file: https://docs.projectcalico.org/v3.10/manifests/calico.yaml
|
3
roles/k8s/handlers/main.yml
Normal file
3
roles/k8s/handlers/main.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
- name: restart kubelet
|
||||||
|
service: name=kubelet state=restarted
|
2
roles/k8s/meta/.galaxy_install_info
Normal file
2
roles/k8s/meta/.galaxy_install_info
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
install_date: Tue Feb 16 21:36:26 2021
|
||||||
|
version: 5.0.1
|
35
roles/k8s/meta/main.yml
Normal file
35
roles/k8s/meta/main.yml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
---
|
||||||
|
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
|
||||||
|
platforms:
|
||||||
|
- name: EL
|
||||||
|
versions:
|
||||||
|
- 7
|
||||||
|
- 8
|
||||||
|
- name: Debian
|
||||||
|
versions:
|
||||||
|
- stretch
|
||||||
|
- buster
|
||||||
|
- name: Ubuntu
|
||||||
|
versions:
|
||||||
|
- xenial
|
||||||
|
- bionic
|
||||||
|
- focal
|
||||||
|
galaxy_tags:
|
||||||
|
- system
|
||||||
|
- containers
|
||||||
|
- docker
|
||||||
|
- rkt
|
||||||
|
- orchestration
|
||||||
|
- kubernetes
|
||||||
|
- k8s
|
||||||
|
- paas
|
||||||
|
- saas
|
||||||
|
- hosting
|
50
roles/k8s/molecule/default/calico.yml
Normal file
50
roles/k8s/molecule/default/calico.yml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
- 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 Docker envs).
|
||||||
|
kubernetes_kubelet_extra_args: "--fail-swap-on=false --cgroup-driver=cgroupfs"
|
||||||
|
docker_install_compose: false
|
||||||
|
|
||||||
|
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.docker
|
||||||
|
- 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
|
46
roles/k8s/molecule/default/converge.yml
Normal file
46
roles/k8s/molecule/default/converge.yml
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
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
|
||||||
|
|
||||||
|
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.docker
|
||||||
|
- 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
|
18
roles/k8s/molecule/default/molecule.yml
Normal file
18
roles/k8s/molecule/default/molecule.yml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
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
|
||||||
|
- /var/lib/docker
|
||||||
|
privileged: true
|
||||||
|
pre_build_image: true
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
playbooks:
|
||||||
|
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
|
2
roles/k8s/molecule/default/requirements.yml
Normal file
2
roles/k8s/molecule/default/requirements.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
- src: geerlingguy.docker
|
35
roles/k8s/tasks/kubelet-setup.yml
Normal file
35
roles/k8s/tasks/kubelet-setup.yml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
---
|
||||||
|
- name: Check for existence of kubelet environment file.
|
||||||
|
stat:
|
||||||
|
path: '{{ kubelet_environment_file_path }}'
|
||||||
|
register: kubelet_environment_file
|
||||||
|
|
||||||
|
- name: Set facts for KUBELET_EXTRA_ARGS task if environment file exists.
|
||||||
|
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.
|
||||||
|
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.
|
||||||
|
lineinfile:
|
||||||
|
path: '{{ kubelet_args_path }}'
|
||||||
|
line: '{{ kubelet_args_line }}'
|
||||||
|
regexp: '{{ kubelet_args_regexp }}'
|
||||||
|
state: present
|
||||||
|
mode: 0644
|
||||||
|
register: kubelet_config_file
|
||||||
|
|
||||||
|
- name: Reload systemd unit if args were changed.
|
||||||
|
systemd:
|
||||||
|
state: restarted
|
||||||
|
daemon_reload: true
|
||||||
|
name: kubelet
|
||||||
|
when: kubelet_config_file is changed
|
58
roles/k8s/tasks/main.yml
Normal file
58
roles/k8s/tasks/main.yml
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
---
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- 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 master.
|
||||||
|
- include_tasks: master-setup.yml
|
||||||
|
when: kubernetes_role == 'master'
|
||||||
|
|
||||||
|
# Set up nodes.
|
||||||
|
- name: Get the kubeadm join command from the Kubernetes master.
|
||||||
|
command: kubeadm token create --print-join-command
|
||||||
|
changed_when: false
|
||||||
|
when: kubernetes_role == 'master'
|
||||||
|
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'
|
82
roles/k8s/tasks/master-setup.yml
Normal file
82
roles/k8s/tasks/master-setup.yml
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
---
|
||||||
|
- 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 }}
|
||||||
|
register: kubeadmin_init
|
||||||
|
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
|
||||||
|
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: "{{ 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'
|
||||||
|
|
||||||
|
- 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'
|
||||||
|
|
||||||
|
- 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 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
|
6
roles/k8s/tasks/node-setup.yml
Normal file
6
roles/k8s/tasks/node-setup.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- name: Join node to Kubernetes master
|
||||||
|
shell: >
|
||||||
|
{{ kubernetes_join_command }}
|
||||||
|
creates=/etc/kubernetes/kubelet.conf
|
||||||
|
tags: ['skip_ansible_lint']
|
26
roles/k8s/tasks/setup-Debian.yml
Normal file
26
roles/k8s/tasks/setup-Debian.yml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure dependencies are installed.
|
||||||
|
apt:
|
||||||
|
name:
|
||||||
|
- apt-transport-https
|
||||||
|
- ca-certificates
|
||||||
|
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
|
||||||
|
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
|
23
roles/k8s/tasks/setup-RedHat.yml
Normal file
23
roles/k8s/tasks/setup-RedHat.yml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure Kubernetes repository exists.
|
||||||
|
yum_repository:
|
||||||
|
name: kubernetes
|
||||||
|
description: Kubernetes
|
||||||
|
enabled: true
|
||||||
|
gpgcheck: true
|
||||||
|
repo_gpgcheck: true
|
||||||
|
baseurl: "{{ kubernetes_yum_base_url }}"
|
||||||
|
gpgkey: "{{ kubernetes_yum_gpg_key }}"
|
||||||
|
|
||||||
|
- name: Add Kubernetes GPG keys.
|
||||||
|
rpm_key:
|
||||||
|
key: "{{ item }}"
|
||||||
|
state: present
|
||||||
|
register: kubernetes_rpm_key
|
||||||
|
with_items: "{{ kubernetes_yum_gpg_key }}"
|
||||||
|
|
||||||
|
- 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
roles/k8s/tasks/sysctl-setup.yml
Normal file
21
roles/k8s/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
|
11
roles/k8s/templates/apt-preferences-kubernetes.j2
Normal file
11
roles/k8s/templates/apt-preferences-kubernetes.j2
Normal file
@ -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
|
3
roles/k8s/vars/Debian.yml
Normal file
3
roles/k8s/vars/Debian.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
procps_package: procps
|
||||||
|
kubelet_environment_file_path: /etc/default/kubelet
|
12
roles/k8s/vars/RedHat.yml
Normal file
12
roles/k8s/vars/RedHat.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
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
|
@ -5,6 +5,16 @@
|
|||||||
# MAD PROPS to geerlingguy; if for some reason you end up reading this, hit me
|
# MAD PROPS to geerlingguy; if for some reason you end up reading this, hit me
|
||||||
# up and I'll buy you a beer or a pizza or something.
|
# up and I'll buy you a beer or a pizza or something.
|
||||||
|
|
||||||
|
# Orchestration
|
||||||
|
# Upstream: https://github.com/geerlingguy/ansible-role-docker
|
||||||
|
- src: geerlingguy.docker
|
||||||
|
version: 3.0.0
|
||||||
|
name: docker
|
||||||
|
# Upstream: https://github.com/geerlingguy/ansible-role-kubernetes
|
||||||
|
- src: geerlingguy.kubernetes
|
||||||
|
version: 5.0.1
|
||||||
|
name: k8s
|
||||||
|
|
||||||
# DB Server stuff
|
# DB Server stuff
|
||||||
# Upstream: https://github.com/geerlingguy/ansible-role-postgresql
|
# Upstream: https://github.com/geerlingguy/ansible-role-postgresql
|
||||||
- src: geerlingguy.postgresql
|
- src: geerlingguy.postgresql
|
||||||
|
1
site.yml
1
site.yml
@ -19,3 +19,4 @@
|
|||||||
- import_playbook: playbooks/web.yml
|
- import_playbook: playbooks/web.yml
|
||||||
- import_playbook: playbooks/game.yml
|
- import_playbook: playbooks/game.yml
|
||||||
- import_playbook: playbooks/desktop.yml
|
- import_playbook: playbooks/desktop.yml
|
||||||
|
- import_playbook: playbooks/k8s.yml
|
||||||
|
Loading…
Reference in New Issue
Block a user