summaryrefslogtreecommitdiffstats
path: root/kud/deployment_infra/playbooks/configure-virtlet.yml
blob: c400cab09bd5a4bb97b5a87691c18ae4ec44a38a (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
---
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2018
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
- hosts: localhost
  vars:
    images_file: /tmp/images.yaml
  pre_tasks:
    - name: Load kud variables
      include_vars:
        file: kud-vars.yml
  roles:
    - role: geerlingguy.docker
      when: virtlet_source_type == "source"
  tasks:
    - name: create Virtlet binary folder
      file:
        state: directory
        path: "{{ virtlet_dest }}"
    - name: apply virtlet extraRuntime label
      command: "/usr/local/bin/kubectl label node {{ item }} extraRuntime=virtlet --overwrite"
      with_inventory_hostnames: virtlet
    - name: create image translations confimap file
      blockinfile:
        path: "{{ images_file }}"
        create: yes
        block: |
          translations:
            - name: ubuntu/14.04
              url: https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
            - name: ubuntu/16.04
              url: https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img
            - name: ubuntu/18.04
              url: https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
            - regexp: 'centos/(\d+)-(\d+)'
              url: 'https://cloud.centos.org/centos/$1/images/CentOS-$1-x86_64-GenericCloud-$2.qcow2'
            - name: fedora
              url: https://dl.fedoraproject.org/pub/fedora/linux/releases/31/Cloud/x86_64/images/Fedora-Cloud-Base-31-1.9.x86_64.qcow2
          {% if lookup('env','http_proxy') != "" %}
          transports:
            "":
              proxy: "{{ lookup('env','http_proxy') }}"
          {% endif %}
    - name: install image translations configmap
      shell: "/usr/local/bin/kubectl create configmap -n kube-system virtlet-image-translations --from-file {{ images_file }} --dry-run -o yaml | /usr/local/bin/kubectl apply -f -"
      ignore_errors: True
    - name: create Virtlet folder
      file:
        state: directory
        path: "{{ virtlet_dest }}"
    - name: getting source code
      block:
      - name: clone Virtlet repo
        git:
          repo: "{{ virtlet_url }}"
          dest: "{{ virtlet_dest }}"
          version: "{{ virtlet_version }}"
          force: yes
      - name: configure proxy values for docker service
        block:
        - name: create docker config folder
          become: yes
          file:
            state: directory
            path: "/etc/systemd/system/docker.service.d"
        - name: Configure docker service to use http_proxy env value
          become: yes
          blockinfile:
            dest: "/etc/systemd/system/docker.service.d/http-proxy.conf"
            create: yes
            block: |
              [Service]
              Environment="HTTP_PROXY={{ lookup('env','http_proxy') }}"
          when:
            - lookup('env','http_proxy') != "fooproxy"
        - name: Configure docker service to use https_proxy env value
          become: yes
          blockinfile:
            dest: "/etc/systemd/system/docker.service.d/https-proxy.conf"
            create: yes
            block: |
              [Service]
              Environment="HTTPS_PROXY={{ lookup('env','https_proxy') }}"
          when:
            - lookup('env','https_proxy') != "fooproxy"
        - name: Configure docker service to use no_proxy env value
          become: yes
          blockinfile:
            dest: "/etc/systemd/system/docker.service.d/no-proxy.conf"
            create: yes
            block: |
              [Service]
              Environment="NO_PROXY={{ lookup('env','no_proxy') }}"
          when:
            - lookup('env','no_proxy') != "fooproxy"
        - name: reload systemd
          become: yes
          command: systemctl daemon-reload
        - name: restart docker service
          become: yes
          service:
            name: docker
            state: restarted
        when: lookup('env','http_proxy') != "fooproxy" or lookup('env','https_proxy') != "fooproxy" or lookup('env','no_proxy') != "fooproxy"
      - name: build virtlet source code
        command: ./cmd.sh build
        args:
          chdir: "{{ virtlet_dest }}/build"
        environment:
          http_proxy: "{{ lookup('env','http_proxy') }}"
          https_proxy: "{{ lookup('env','https_proxy') }}"
          no_proxy: "{{ lookup('env','no_proxy') }}"
      when: virtlet_source_type == "source"
    - name: download virtletctl
      get_url:
        url: "{{ virtlet_url }}"
        dest: "{{ virtlet_dest }}/virtletctl"
      when: virtlet_source_type == "binary"
    - name: set virtletctl execution permissions
      file:
        path: "{{ virtlet_dest }}/virtletctl"
        mode: "+x"
    - name: install virtletctl as kubectl plugin
      become: yes
      command: "mv {{ virtlet_dest }}/virtletctl /usr/local/bin/kubectl-virt"
    - name: create Virtlet k8s objects
      shell: "/usr/local/bin/kubectl virt gen | /usr/local/bin/kubectl apply -f -"
      ignore_errors: True
    - name: wait for Virtlet daemonset
      shell: "/usr/local/bin/kubectl get ds virtlet -n=kube-system -o=jsonpath --template={.status.numberReady}"
      register: daemonset
      until:
        - '1'
      retries: 6
      delay: 10

- hosts: virtlet
  tasks:
    - name: Load kud variables
      include_vars:
        file: kud-vars.yml
    - name: create CRIProxy binary folder
      file:
        state: directory
        path: "{{ criproxy_dest }}"
    - name: disable AppArmor in all nodes
      become: yes
      service:
        name: apparmor
        state: stopped
        enabled: no
      when: ansible_os_family == "Debian"
    - name: modify args for kubelet service
      become: yes
      lineinfile:
        dest: /etc/systemd/system/kubelet.service
        line: "                --container-runtime=remote --container-runtime-endpoint=unix:///run/criproxy.sock --image-service-endpoint=unix:///run/criproxy.sock --enable-controller-attach-detach=false \\"
        insertafter: '^ExecStart=/usr/local/bin/kubelet *'
        state: present
    - name: create dockershim service
      become: yes
      blockinfile:
        path: /etc/systemd/system/dockershim.service
        create: yes
        block: |
          [Unit]
          Description=dockershim for criproxy

          [Service]
          EnvironmentFile=-/etc/kubernetes/kubelet.env
          ExecStartPre=-/bin/mkdir -p /var/lib/kubelet/volume-plugins
          ExecStart=/usr/local/bin/kubelet --experimental-dockershim --port 11250 \
                $KUBE_LOGTOSTDERR \
                $KUBE_LOG_LEVEL \
                $KUBELET_API_SERVER \
                $KUBELET_ADDRESS \
                $KUBELET_PORT \
                $KUBELET_HOSTNAME \
                $KUBE_ALLOW_PRIV \
                $KUBELET_ARGS \
                $DOCKER_SOCKET \
                $KUBELET_NETWORK_PLUGIN \
                $KUBELET_VOLUME_PLUGIN \
                $KUBELET_CLOUDPROVIDER
          Restart=always
          StartLimitInterval=0
          RestartSec=10

          [Install]
          RequiredBy=criproxy.service
    - name: getting source code
      block:
      - name: clone CRIProxy repo
        git:
          repo: "{{ criproxy_url }}"
          dest: "{{ criproxy_dest }}"
          version: "{{ criproxy_version }}"
          force: yes
      - name: build criproxy source code
        command: ./build-package.sh
        args:
          chdir: "{{ criproxy_dest }}"
      when: criproxy_source_type == "source"
    - name: download CRIproxy package
      get_url:
        url: "{{ criproxy_url }}"
        dest: "{{ criproxy_dest }}/criproxy"
      when: criproxy_source_type == "binary"
    - name: set criproxy execution permissions
      file:
        path: "{{ criproxy_dest }}/criproxy"
        mode: "+x"
    - name: create criproxy service
      become: yes
      blockinfile:
        path: /etc/systemd/system/criproxy.service
        create: yes
        block: |
          [Unit]
          Description=CRI Proxy

          [Service]
          ExecStart={{ criproxy_dest }}/criproxy -v 3 -logtostderr -connect /var/run/dockershim.sock,virtlet.cloud:/run/virtlet.sock -listen /run/criproxy.sock
          Restart=always
          StartLimitInterval=0
          RestartSec=10

          [Install]
          WantedBy=kubelet.service
    - name: start criproxy and dockershim services
      become: yes
      service:
        name: "{{ item }}"
        state: started
        enabled: yes
      with_items:
      - dockershim
      - criproxy
    - name: restart kubelet services
      become: yes
      service:
        name: kubelet
        state: restarted