Add role to install kubernetes

Optionally, and by default, installs a Minikube cluster that runs
locally.

Change-Id: Ie6d0b73e6b3bdb77eee133a5f663133fd037aba0
This commit is contained in:
David Shrewsbury 2018-09-27 13:57:50 -04:00
parent a01a13e49b
commit 230a0f6cc2
4 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,8 @@
An ansible role to install kubernetes.
**Role Variables**
.. zuul:rolevar:: install_kubernetes_with_cluster
:default: True
If true, installs a Minikube cluster.

View File

@ -0,0 +1 @@
install_kubernetes_with_cluster: True

View File

@ -0,0 +1,21 @@
- name: Install apt key
become: yes
apt_key:
url: "https://packages.cloud.google.com/apt/doc/apt-key.gpg"
state: present
- name: Add kubernetes repo
become: yes
apt_repository:
repo: deb http://apt.kubernetes.io/ kubernetes-xenial main
state: present
- name: Install kubernetes packages
become: yes
apt:
name: kubectl
update_cache: yes
- name: Run cluster tasks
include_tasks: minikube.yaml
when: install_kubernetes_with_cluster

View File

@ -0,0 +1,48 @@
- name: Check for Minikube install
stat:
path: /tmp/minikube
register: stat_result
- name: Download Minikube
get_url:
url: https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
dest: /tmp/minikube
mode: 0755
when: stat_result.stat.exists == False
- name: Run install-docker role
include_role:
name: install-docker
- name: Create .kube directory
file:
path: "{{ ansible_user_dir }}/.kube"
state: directory
mode: 0755
- name: Create .kube/config file
file:
path: "{{ ansible_user_dir }}/.kube/config"
state: touch
mode: 0644
- name: Create .minikube directory
file:
path: "{{ ansible_user_dir }}/.minikube"
state: directory
mode: 0755
- name: Start Minikube
become: yes
command: /tmp/minikube --vm-driver=none start
environment:
MINIKUBE_WANTUPDATENOTIFICATION: false
MINIKUBE_WANTREPORTERRORPROMPT: false
MINIKUBE_WANTNONEDRIVERWARNING: false
MINIKUBE_WANTKUBECTLDOWNLOADMSG: false
CHANGE_MINIKUBE_NONE_USER: true
MINIKUBE_HOME: "{{ ansible_user_dir }}"
KUBECONFIG: "{{ ansible_user_dir }}/.kube/config"
- name: Get cluster info
command: kubectl cluster-info