More updates to make things work better in various situations.

This commit is contained in:
Jeff Geerling 2018-05-09 11:15:30 -05:00
parent 7bf95595f7
commit 751369584d
4 changed files with 63 additions and 2 deletions

View File

@ -20,6 +20,18 @@ Available variables are listed below, along with default values (see `defaults/m
- name: kubernetes-cni - name: kubernetes-cni
state: present state: present
TODO.
kubernetes_allow_swap: False
TODO.
kubernetes_allow_pods_on_master: True
TODO.
kubernetes_enable_web_ui: True
TODO. TODO.
kubernetes_apt_release_channel: main kubernetes_apt_release_channel: main

View File

@ -9,6 +9,11 @@ kubernetes_packages:
- name: kubernetes-cni - name: kubernetes-cni
state: present state: present
kubernetes_allow_swap: False
kubernetes_allow_pods_on_master: True
kubernetes_enable_web_ui: True
kubernetes_apt_release_channel: main kubernetes_apt_release_channel: main
kubernetes_apt_repository: "deb http://apt.kubernetes.io/ kubernetes-{{ ansible_distribution_release }} {{ kubernetes_apt_release_channel }}" kubernetes_apt_repository: "deb http://apt.kubernetes.io/ kubernetes-{{ ansible_distribution_release }} {{ kubernetes_apt_release_channel }}"
kubernetes_apt_ignore_key_error: False kubernetes_apt_ignore_key_error: False

View File

@ -15,12 +15,26 @@
notify: restart kubelet notify: restart kubelet
with_items: "{{ kubernetes_packages }}" with_items: "{{ kubernetes_packages }}"
- name: Allow kubelet to run with swap enabled (if configured).
lineinfile:
path: /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
line: 'Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"'
regexp: 'Environment="KUBELET_EXTRA_ARGS=--fail-swap-on.+'
insertafter: '^Environment='
state: present
when: kubernetes_allow_swap
- name: Ensure kubelet is started and enabled at boot. - name: Ensure kubelet is started and enabled at boot.
service: service:
name: kubelet name: kubelet
state: started state: started
enabled: yes enabled: yes
- name: Check if Kubernetes has already been initialized.
stat:
path: /etc/kubernetes/admin.conf
register: kubernetes_init_stat
- name: Initialize the Kubernetes master with kubeadm init. - name: Initialize the Kubernetes master with kubeadm init.
command: > command: >
kubeadm init kubeadm init
@ -30,10 +44,37 @@
--ignore-preflight-errors=all --ignore-preflight-errors=all
register: kubeadmin_init register: kubeadmin_init
failed_when: False failed_when: False
when: kubernetes_init_stat.stat.exists == False
- name: Print the init output to screen. - name: Print the init output to screen.
debug: var=kubeadmin_init.stdout debug: var=kubeadmin_init.stdout
when: kubernetes_init_stat.stat.exists == False
# TODO: Set up Flannel. - name: Ensure .kube directory exists.
file:
path: ~/.kube
state: directory
# TODO: Allow pods on master with `kubectl taint nodes --all node-role.kubernetes.io/master-` - 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 https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
- kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
# 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
- kubernetes_init_stat.stat.exists == False
- name: Enable the Kubernetes Web Dashboard UI (if configured).
command: "kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml"
when: kubernetes_enable_web_ui

View File

@ -1,6 +1,9 @@
--- ---
- hosts: all - hosts: all
vars:
kubernetes_allow_swap: True
pre_tasks: pre_tasks:
- name: Update apt cache. - name: Update apt cache.
apt: update_cache=yes cache_valid_time=600 apt: update_cache=yes cache_valid_time=600