commit aa31c38f75e85a439498e7fc82318454b6a4b7c7 Author: Jeff Geerling Date: Wed May 9 09:19:11 2018 -0500 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c9b2377 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.retry +tests/test.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3b90107 --- /dev/null +++ b/.travis.yml @@ -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/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6eb558e --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..701bd9d --- /dev/null +++ b/README.md @@ -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/). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..58f3631 --- /dev/null +++ b/defaults/main.yml @@ -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 }}" diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..ebdb957 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart kubelet + service: name=kubelet state=restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..0bd3877 --- /dev/null +++ b/meta/main.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..b1b8c8c --- /dev/null +++ b/tasks/main.yml @@ -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-` diff --git a/tasks/setup-Debian.yml b/tasks/setup-Debian.yml new file mode 100644 index 0000000..3604a1e --- /dev/null +++ b/tasks/setup-Debian.yml @@ -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 diff --git a/tasks/setup-RedHat.yml b/tasks/setup-RedHat.yml new file mode 100644 index 0000000..bffc54a --- /dev/null +++ b/tasks/setup-RedHat.yml @@ -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 diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..6fb2117 --- /dev/null +++ b/tests/README.md @@ -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)` diff --git a/tests/requirements.yml b/tests/requirements.yml new file mode 100644 index 0000000..3a013f3 --- /dev/null +++ b/tests/requirements.yml @@ -0,0 +1,2 @@ +--- +- src: geerlingguy.docker diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..17a1bcd --- /dev/null +++ b/tests/test.yml @@ -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