Extract kubectl commands to resource yaml files and use kube module

This commit is contained in:
Raj Perera 2017-06-19 11:00:26 -04:00 committed by jwfang
parent c0db1499fd
commit a22868e7d1
5 changed files with 53 additions and 24 deletions

View file

@ -120,3 +120,14 @@ enable_network_policy: false
## at the moment. ## at the moment.
authorization_mode: ['AlwaysAllow'] authorization_mode: ['AlwaysAllow']
rbac_enabled: "{{ 'RBAC' in authorization_mode }}" rbac_enabled: "{{ 'RBAC' in authorization_mode }}"
ssl_ca_dirs: "[
{% if ansible_os_family in ['CoreOS', 'Container Linux by CoreOS'] -%}
'/usr/share/ca-certificates',
{% elif ansible_os_family == 'RedHat' -%}
'/etc/pki/tls',
'/etc/pki/ca-trust',
{% elif ansible_os_family == 'Debian' -%}
'/usr/share/ca-certificates',
{% endif -%}
]"

View file

@ -10,19 +10,31 @@
mode: 0755 mode: 0755
register: helm_container register: helm_container
- name: Helm | Configure tiller service account for RBAC - name: Helm | Lay Down Helm Manifests (RBAC)
command: kubectl create serviceaccount tiller --namespace={{ system_namespace }} template:
ignore_errors: yes src: "manifests/{{item.file}}"
when: rbac_enabled dest: "{{kube_config_dir}}/{{item.file}}"
with_items:
- {name: tiller, file: tiller-sa.yml, type: sa}
- {name: tiller, file: tiller-clusterrolebinding.yml, type: clusterrolebinding}
register: manifests
when: dns_mode != 'none' and inventory_hostname == groups['kube-master'][0] and rbac_enabled
- name: Helm | Configure tiller rolebindings for RBAC - name: Helm | Apply Helm Manifests (RBAC)
command: kubectl create clusterrolebinding tiller --clusterrole=cluster-admin --serviceaccount={{ system_namespace }}:tiller kube:
ignore_errors: yes name: "{{item.item.name}}"
when: rbac_enabled namespace: "{{ system_namespace }}"
kubectl: "{{bin_dir}}/kubectl"
resource: "{{item.item.type}}"
filename: "{{kube_config_dir}}/{{item.item.file}}"
state: "{{item.changed | ternary('latest','present') }}"
with_items: "{{ manifests.results }}"
failed_when: manifests|failed and "Error from server (AlreadyExists)" not in manifests.msg
when: dns_mode != 'none' and inventory_hostname == groups['kube-master'][0] and rbac_enabled
- name: Helm | Install/upgrade helm - name: Helm | Install/upgrade helm
command: "{{ bin_dir }}/helm init --upgrade --tiller-image={{ tiller_image_repo }}:{{ tiller_image_tag }}" command: "{{ bin_dir }}/helm init --upgrade --tiller-image={{ tiller_image_repo }}:{{ tiller_image_tag }}"
when: helm_container.changed when: helm_container.changed or manifests|changed
- name: Helm | Patch tiller deployment for RBAC - name: Helm | Patch tiller deployment for RBAC
command: kubectl patch deployment tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}' -n {{ system_namespace }} command: kubectl patch deployment tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}' -n {{ system_namespace }}

View file

@ -0,0 +1,13 @@
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: tiller
namespace: {{ system_namespace }}
subjects:
- kind: ServiceAccount
name: tiller
namespace: {{ system_namespace }}
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io

View file

@ -0,0 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: tiller
namespace: {{ system_namespace }}
labels:
kubernetes.io/cluster-service: "true"

View file

@ -1,18 +1,4 @@
--- ---
- name: install | Set SSL CA directories
set_fact:
ssl_ca_dirs: "[
{% if ansible_os_family in ['CoreOS', 'Container Linux by CoreOS'] -%}
'/usr/share/ca-certificates',
{% elif ansible_os_family == 'RedHat' -%}
'/etc/pki/tls',
'/etc/pki/ca-trust',
{% elif ansible_os_family == 'Debian' -%}
'/usr/share/ca-certificates',
{% endif -%}
]"
tags: facts
- include: "install_{{ kubelet_deployment_type }}.yml" - include: "install_{{ kubelet_deployment_type }}.yml"
- name: install | Write kubelet systemd init file - name: install | Write kubelet systemd init file