summaryrefslogtreecommitdiff
path: root/extraconfig/services/kubernetes-master.yaml
blob: 5ac361a4670330bc66dced632f02c17a4d740411 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
heat_template_version: ocata

description: Triggers a Mistral workflow for the deployment of Kubernetes

parameters:
  RoleNetIpMap:
    default: {}
    type: json
  ServiceData:
    default: {}
    description: Dictionary packing service data
    type: json
  ServiceNetMap:
    default: {}
    description: Mapping of service_name -> network name. Typically set
                 via parameter_defaults in the resource registry.  This
                 mapping overrides those in ServiceNetMapDefaults.
    type: json
  DefaultPasswords:
    default: {}
    type: json
  RoleName:
    default: ''
    description: Role name on which the service is applied
    type: string
  RoleParameters:
    default: {}
    description: Parameters specific to the role
    type: json
  EndpointMap:
    default: {}
    description: Mapping of service endpoint -> protocol. Typically set
                 via parameter_defaults in the resource registry.
    type: json

outputs:
  role_data:
    description: Role data for the Kubernetes Service
    value:
      service_name: kubernetes_master
      config_settings:
        tripleo.kubernetes_master.firewall_rules:
          '200 kubernetes-master api':
            dport: 6443
            proto: tcp
          '200 kubernetes-master etcd':
            dport:
              - 2379
              - 2380
            proto: tcp
          '200 kubernetes-master flannel':
            dport:
              - 8285
              - 8472
            proto: udp
      upgrade_tasks: []
      step_config: ''
      external_deploy_tasks:
        # FIXME: remove this block when kubespray is packaged
        - name: kubernetes_master step 2 kubespray repository
          when: step == '2'
          block:
            - name: check kubespray directory existence
              stat:
                path: /usr/share/kubespray
              register: kubespray_stat
            - name: clone kubespray repo
              git:
                repo: https://github.com/kubernetes-incubator/kubespray
                dest: /usr/share/kubespray
                update: no
              become: yes
              become_user: root
              when: not kubespray_stat.stat.exists
        - name: kubernetes_master step 2
          when: step == '2'
          block:
            - name: create kubespray temp dirs
              file:
                path: "{{item}}"
                state: directory
              with_items:
                - "{{playbook_dir}}/kubespray"
                - "{{playbook_dir}}/kubespray/artifacts"
            - name: generate kubespray inventory
              copy:
                dest: "{{playbook_dir}}/kubespray/inventory.yml"
                content: |
                  kube-master:
                    hosts:
                      {% for host in groups['kubernetes_master'] -%}
                      {{ hostvars.raw_get(host)['ansible_hostname'] }}:
                        ansible_user: {{ hostvars.raw_get(host)['ansible_user'] | default(hostvars.raw_get(host)['ansible_ssh_user']) | default('root') }}
                        ansible_host: {{ hostvars.raw_get(host)['ansible_host'] | default(host) }}
                      {% endfor %}

                  kube-node:

                    hosts:
                      {% for host in groups['kubernetes_worker'] -%}
                      {{ hostvars.raw_get(host)['ansible_hostname'] }}:
                        ansible_user: {{ hostvars.raw_get(host)['ansible_user'] | default(hostvars.raw_get(host)['ansible_ssh_user']) | default('root') }}
                        ansible_host: {{ hostvars.raw_get(host)['ansible_host'] | default(host) }}
                      {% endfor %}

                  etcd:
                    children:
                      kube-master: {}

                  k8s-cluster:
                    children:
                      kube-master: {}
                      kube-node: {}
            - name: generate kubespray global vars
              copy:
                dest: "{{playbook_dir}}/kubespray/global_vars.yml"
                content: |
                  kubeconfig_localhost: true
                  kubectl_localhost: true
                  artifacts_dir: '{{playbook_dir}}/kubespray/artifacts'
            - name: generate kubespray playbook
              copy:
                dest: "{{playbook_dir}}/kubespray/playbook.yml"
                content: |
                  - include: /usr/share/kubespray/cluster.yml
            - name: set kubespray command
              set_fact:
                # NOTE: We could let kubespray configure docker
                # (remove --skip-tags docker) and run it in step 1
                # when this RFE is implemented:
                # https://github.com/kubernetes-incubator/kubespray/issues/1836
                kubespray_command: >-
                  {%- if kubespray_command is defined -%}
                  {{kubespray_command}}
                  {%- else -%}
                  ansible-playbook
                  -b
                  -i '{{playbook_dir}}/kubespray/inventory.yml'
                  --skip-tags docker,bastion-ssh-config
                  --extra-vars '@{{playbook_dir}}/kubespray/global_vars.yml'
                  '{{playbook_dir}}/kubespray/playbook.yml'
                  {%- endif -%}
            - name: print kubespray command
              debug:
                var: kubespray_command
            - name: run kubespray (immediate log at {{playbook_dir}}/kubespray/playbook.log)
              shell: |
                {{kubespray_command}} 2>&1 | tee {{playbook_dir}}/kubespray/playbook.log
                exit ${PIPESTATUS[0]}
              register: outputs
            - name: print kubespray outputs
              debug:
                var: (outputs.stderr|default('')).split('\n')|union(outputs.stdout_lines|default([]))
              failed_when: outputs|failed
              when: outputs is defined