You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.1 KiB

[jjo] add DIND support to contrib/ (#3468) * [jjo] add DIND support to contrib/ - add contrib/dind with ansible playbook to create "node" containers, and setup them to mimic host nodes as much as possible (using Ubuntu images), see contrib/dind/README.md - nodes' /etc/hosts editing via `blockinfile` and `lineinfile` need `unsafe_writes: yes` because /etc/hosts are mounted by docker, and thus can't be handled atomically (modify copy + rename) * dind-host role: set node container hostname on creation * add "Resulting deployment" section with some CLI outputs * typo * selectable node_distro: debian, ubuntu * some fixes for node_distro: ubuntu * cpu optimization: add early `pkill -STOP agetty` * typo * add centos dind support ;) * add kubespray-dind.yaml, support fedora - add kubespray-dind.yaml (former custom.yaml at README.md) - rework README.md as per above - use some YAML power to share distros' commonality - add fedora support * create unique /etc/machine-id and other updates - create unique /etc/machine-id in each docker node, used as seed for e.g. weave mac addresses - with above, now netchecker 100% passes WoHooOO! :tada: :tada: :tada: - updated README.md output from (1.12.1, verified netcheck) * minor typos * fix centos node creation, needs earlier udevadm removal to avoid flaky facts, also verified netcheck Ok \o/ * add Q&D test-distros.sh, back to manual /etc/machine-id hack * run-test-distros.sh cosmetics and minor fixes * run-test-distros.sh: $rc fix and minor formatting changes * run-test-distros.sh output cosmetics
6 years ago
  1. - name: set_fact distro_setup
  2. set_fact:
  3. distro_setup: "{{ distro_settings[node_distro] }}"
  4. - name: set_fact other distro settings
  5. set_fact:
  6. distro_image: "{{ distro_setup['image'] }}"
  7. distro_init: "{{ distro_setup['init'] }}"
  8. distro_pid1_exe: "{{ distro_setup['pid1_exe'] }}"
  9. distro_raw_setup: "{{ distro_setup['raw_setup'] }}"
  10. distro_raw_setup_done: "{{ distro_setup['raw_setup_done'] }}"
  11. distro_agetty_svc: "{{ distro_setup['agetty_svc'] }}"
  12. - name: Create dind node containers from "containers" inventory section
  13. docker_container:
  14. image: "{{ distro_image }}"
  15. name: "{{ item }}"
  16. state: started
  17. hostname: "{{ item }}"
  18. command: "{{ distro_init }}"
  19. #recreate: yes
  20. privileged: true
  21. tmpfs:
  22. - /sys/module/nf_conntrack/parameters
  23. volumes:
  24. - /boot:/boot
  25. - /lib/modules:/lib/modules
  26. - "{{ item }}:/dind/docker"
  27. register: containers
  28. with_items: "{{groups.containers}}"
  29. tags:
  30. - addresses
  31. - name: Gather list of containers IPs
  32. set_fact:
  33. addresses: "{{ containers.results | map(attribute='ansible_facts') | map(attribute='docker_container') | map(attribute='NetworkSettings') | map(attribute='IPAddress') | list }}"
  34. tags:
  35. - addresses
  36. - name: Create inventory_builder helper already set with the list of node containers' IPs
  37. template:
  38. src: inventory_builder.sh.j2
  39. dest: /tmp/kubespray.dind.inventory_builder.sh
  40. mode: 0755
  41. tags:
  42. - addresses
  43. - name: Install needed packages into node containers via raw, need to wait for possible systemd packages to finish installing
  44. raw: |
  45. # agetty processes churn a lot of cpu time failing on inexistent ttys, early STOP them, to rip them in below task
  46. pkill -STOP agetty || true
  47. {{ distro_raw_setup_done }} && echo SKIPPED && exit 0
  48. until [ "$(readlink /proc/1/exe)" = "{{ distro_pid1_exe }}" ] ; do sleep 1; done
  49. {{ distro_raw_setup }}
  50. delegate_to: "{{ item._ansible_item_label }}"
  51. with_items: "{{ containers.results }}"
  52. register: result
  53. changed_when: result.stdout.find("SKIPPED") < 0
  54. - name: Remove gettys from node containers
  55. raw: |
  56. until test -S /var/run/dbus/system_bus_socket; do sleep 1; done
  57. systemctl disable {{ distro_agetty_svc }}
  58. systemctl stop {{ distro_agetty_svc }}
  59. delegate_to: "{{ item._ansible_item_label }}"
  60. with_items: "{{ containers.results }}"
  61. changed_when: false
  62. # Running systemd-machine-id-setup doesn't create a unique id for each node container on Debian,
  63. # handle manually
  64. - name: Re-create unique machine-id (as we may just get what comes in the docker image), needed by some CNIs for mac address seeding (notably weave)
  65. raw: |
  66. echo {{ item | hash('sha1') }} > /etc/machine-id.new
  67. mv -b /etc/machine-id.new /etc/machine-id
  68. cmp /etc/machine-id /etc/machine-id~ || true
  69. systemctl daemon-reload
  70. delegate_to: "{{ item._ansible_item_label }}"
  71. with_items: "{{ containers.results }}"
  72. - name: Early hack image install to adapt for DIND
  73. raw: |
  74. rm -fv /usr/bin/udevadm /usr/sbin/udevadm
  75. delegate_to: "{{ item._ansible_item_label }}"
  76. with_items: "{{ containers.results }}"
  77. register: result
  78. changed_when: result.stdout.find("removed") >= 0