mirror of
https://github.com/geerlingguy/ansible-role-kubernetes.git
synced 2024-12-21 19:06:56 +01:00
Initial commit.
This commit is contained in:
commit
aa31c38f75
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.retry
|
||||
tests/test.sh
|
26
.travis.yml
Normal file
26
.travis.yml
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
services: docker
|
||||
|
||||
env:
|
||||
- distro: centos7
|
||||
- distro: ubuntu1604
|
||||
- distro: debian9
|
||||
- distro: fedora27
|
||||
|
||||
script:
|
||||
# Configure test script so we can run extra tests after playbook is run.
|
||||
- export container_id=$(date +%s)
|
||||
- export cleanup=false
|
||||
|
||||
# Download test shim.
|
||||
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
|
||||
- chmod +x ${PWD}/tests/test.sh
|
||||
|
||||
# Run tests.
|
||||
- ${PWD}/tests/test.sh
|
||||
|
||||
# Test whether Kubernetes is running correctly.
|
||||
# - docker exec --tty ${container_id} command-goes-here
|
||||
|
||||
notifications:
|
||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
20
LICENSE
Normal file
20
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.
|
50
README.md
Normal file
50
README.md
Normal file
@ -0,0 +1,50 @@
|
||||
# Ansible Role: Kubernetes
|
||||
|
||||
[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-kubernetes.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-kubernetes)
|
||||
|
||||
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: kubeadm
|
||||
state: present
|
||||
- name: kubernetes-cni
|
||||
state: present
|
||||
|
||||
TODO.
|
||||
|
||||
kubernetes_apt_release_channel: main
|
||||
kubernetes_apt_repository: "deb http://apt.kubernetes.io/ kubernetes-{{ ansible_distribution_release }} {{ kubernetes_apt_release_channel }}"
|
||||
kubernetes_apt_ignore_key_error: False
|
||||
|
||||
TODO.
|
||||
|
||||
## Dependencies
|
||||
|
||||
None.
|
||||
|
||||
## Example Playbook
|
||||
|
||||
```yaml
|
||||
- hosts: all
|
||||
roles:
|
||||
- geerlingguy.docker
|
||||
- geerlingguy.kubernetes
|
||||
```
|
||||
|
||||
## 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/).
|
17
defaults/main.yml
Normal file
17
defaults/main.yml
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
kubernetes_packages:
|
||||
- name: kubelet
|
||||
state: present
|
||||
- name: kubeadm
|
||||
state: present
|
||||
- name: kubectl
|
||||
state: present
|
||||
- name: kubernetes-cni
|
||||
state: present
|
||||
|
||||
kubernetes_apt_release_channel: main
|
||||
kubernetes_apt_repository: "deb http://apt.kubernetes.io/ kubernetes-{{ ansible_distribution_release }} {{ kubernetes_apt_release_channel }}"
|
||||
kubernetes_apt_ignore_key_error: False
|
||||
|
||||
kubernetes_yum_arch: x86_64
|
||||
kubernetes_yum_repo_url: "https://packages.cloud.google.com/yum/repos/kubernetes-el{{ ansible_distribution_major_version }}-{{ kubernetes_yum_arch }}"
|
3
handlers/main.yml
Normal file
3
handlers/main.yml
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
- name: restart kubelet
|
||||
service: name=kubelet state=restarted
|
34
meta/main.yml
Normal file
34
meta/main.yml
Normal file
@ -0,0 +1,34 @@
|
||||
---
|
||||
dependencies: []
|
||||
|
||||
galaxy_info:
|
||||
author: geerlingguy
|
||||
description: Kubernetes for Linux.
|
||||
company: "Midwestern Mac, LLC"
|
||||
license: "license (BSD, MIT)"
|
||||
min_ansible_version: 2.4
|
||||
platforms:
|
||||
- name: EL
|
||||
versions:
|
||||
- 7
|
||||
- name: Fedora
|
||||
versions:
|
||||
- all
|
||||
- name: Debian
|
||||
versions:
|
||||
- stretch
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- xenial
|
||||
- bionic
|
||||
galaxy_tags:
|
||||
- system
|
||||
- containers
|
||||
- docker
|
||||
- rkt
|
||||
- orchestration
|
||||
- kubernetes
|
||||
- k8s
|
||||
- paas
|
||||
- saas
|
||||
- hosting
|
37
tasks/main.yml
Normal file
37
tasks/main.yml
Normal file
@ -0,0 +1,37 @@
|
||||
---
|
||||
- include_tasks: setup-RedHat.yml
|
||||
when: ansible_os_family == 'RedHat'
|
||||
|
||||
- include_tasks: setup-Debian.yml
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
- name: Ensure depdencies 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 }}"
|
||||
|
||||
- name: Ensure kubelet is started and enabled at boot.
|
||||
service:
|
||||
name: kubelet
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: Initialize the Kubernetes master with kubeadm init.
|
||||
command: >
|
||||
kubeadm init
|
||||
--pod-network-cidr=10.0.1.0/16
|
||||
--apiserver-advertise-address={{ ansible_default_ipv4.address }}
|
||||
--kubernetes-version stable-1.10
|
||||
--ignore-preflight-errors=all
|
||||
register: kubeadmin_init
|
||||
|
||||
- name: Print the init output to screen.
|
||||
debug: var=kubeadmin_init.stdout
|
||||
|
||||
# TODO: Set up Flannel.
|
||||
# TODO: Allow pods on master with `kubectl taint nodes --all node-role.kubernetes.io/master-`
|
21
tasks/setup-Debian.yml
Normal file
21
tasks/setup-Debian.yml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
- name: Ensure dependencies are installed.
|
||||
apt:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
with_items:
|
||||
- apt-transport-https
|
||||
- ca-certificates
|
||||
|
||||
- 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: yes
|
13
tasks/setup-RedHat.yml
Normal file
13
tasks/setup-RedHat.yml
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
- name: Add Kubernetes GPG key.
|
||||
rpm_key:
|
||||
key: https://packages.cloud.google.com/yum/doc/yum-key.gpg
|
||||
state: present
|
||||
|
||||
- name: Add Kubernetes repository.
|
||||
get_url:
|
||||
url: "{{ kubernetes_yum_repo_url }}"
|
||||
dest: '/etc/yum.repos.d/kubernetes.repo'
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
11
tests/README.md
Normal file
11
tests/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Ansible Role tests
|
||||
|
||||
To run the test playbook(s) in this directory:
|
||||
|
||||
1. Install and start Docker.
|
||||
1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`:
|
||||
- `wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/`
|
||||
1. Make the test shim executable: `chmod +x tests/test.sh`.
|
||||
1. Run (from the role root directory) `distro=[distro] playbook=[playbook] ./tests/test.sh`
|
||||
|
||||
If you don't want the container to be automatically deleted after the test playbook is run, add the following environment variables: `cleanup=false container_id=$(date +%s)`
|
2
tests/requirements.yml
Normal file
2
tests/requirements.yml
Normal file
@ -0,0 +1,2 @@
|
||||
---
|
||||
- src: geerlingguy.docker
|
16
tests/test.yml
Normal file
16
tests/test.yml
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
- hosts: all
|
||||
|
||||
pre_tasks:
|
||||
- name: Update apt cache.
|
||||
apt: update_cache=yes cache_valid_time=600
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
- name: Ensure test dependencies are installed.
|
||||
package: name=iproute state=present
|
||||
|
||||
- action: setup
|
||||
|
||||
roles:
|
||||
- geerlingguy.docker
|
||||
- role_under_test
|
Loading…
Reference in New Issue
Block a user