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.

176 lines
8.2 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
[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. # Kubespray DIND experimental setup
  2. This ansible playbook creates local docker containers
  3. to serve as Kubernetes "nodes", which in turn will run
  4. "normal" Kubernetes docker containers, a mode usually
  5. called DIND (Docker-IN-Docker).
  6. The playbook has two roles:
  7. - dind-host: creates the "nodes" as containers in localhost, with
  8. appropriate settings for DIND (privileged, volume mapping for dind
  9. storage, etc).
  10. - dind-cluster: customizes each node container to have required
  11. system packages installed, and some utils (swapoff, lsattr)
  12. symlinked to /bin/true to ease mimicking a real node.
  13. This playbook has been test with Ubuntu 16.04 as host and ubuntu:16.04
  14. as docker images (note that dind-cluster has specific customization
  15. for these images).
  16. The playbook also creates a `/tmp/kubespray.dind.inventory_builder.sh`
  17. helper (wraps up running `contrib/inventory_builder/inventory.py` with
  18. node containers IPs and prefix).
  19. ## Deploying
  20. See below for a complete successful run:
  21. 1. Create the node containers
  22. ~~~~
  23. # From the kubespray root dir
  24. cd contrib/dind
  25. pip install -r requirements.txt
  26. ansible-playbook -i hosts dind-cluster.yaml
  27. # Back to kubespray root
  28. cd ../..
  29. ~~~~
  30. NOTE: if the playbook run fails with something like below error
  31. message, you may need to specifically set `ansible_python_interpreter`,
  32. see `./hosts` file for an example expanded localhost entry.
  33. ~~~
  34. failed: [localhost] (item=kube-node1) => {"changed": false, "item": "kube-node1", "msg": "Failed to import docker or docker-py - No module named requests.exceptions. Try `pip install docker` or `pip install docker-py` (Python 2.6)"}
  35. ~~~
  36. 2. Customize kubespray-dind.yaml
  37. Note that there's coupling between above created node containers
  38. and `kubespray-dind.yaml` settings, in particular regarding selected `node_distro`
  39. (as set in `group_vars/all/all.yaml`), and docker settings.
  40. ~~~
  41. $EDITOR contrib/dind/kubespray-dind.yaml
  42. ~~~
  43. 3. Prepare the inventory and run the playbook
  44. ~~~
  45. INVENTORY_DIR=inventory/local-dind
  46. mkdir -p ${INVENTORY_DIR}
  47. rm -f ${INVENTORY_DIR}/hosts.ini
  48. CONFIG_FILE=${INVENTORY_DIR}/hosts.ini /tmp/kubespray.dind.inventory_builder.sh
  49. ansible-playbook --become -e ansible_ssh_user=debian -i ${INVENTORY_DIR}/hosts.ini cluster.yml --extra-vars @contrib/dind/kubespray-dind.yaml
  50. ~~~
  51. NOTE: You could also test other distros without editing files by
  52. passing `--extra-vars` as per below commandline,
  53. replacing `DISTRO` by either `debian`, `ubuntu`, `centos`, `fedora`:
  54. ~~~
  55. cd contrib/dind
  56. ansible-playbook -i hosts dind-cluster.yaml --extra-vars node_distro=DISTRO
  57. cd ../..
  58. CONFIG_FILE=inventory/local-dind/hosts.ini /tmp/kubespray.dind.inventory_builder.sh
  59. ansible-playbook --become -e ansible_ssh_user=DISTRO -i inventory/local-dind/hosts.ini cluster.yml --extra-vars @contrib/dind/kubespray-dind.yaml --extra-vars bootstrap_os=DISTRO
  60. ~~~
  61. ## Resulting deployment
  62. See below to get an idea on how a completed deployment looks like,
  63. from the host where you ran kubespray playbooks.
  64. ### node_distro: debian
  65. Running from an Ubuntu Xenial host:
  66. ~~~
  67. $ uname -a
  68. Linux ip-xx-xx-xx-xx 4.4.0-1069-aws #79-Ubuntu SMP Mon Sep 24
  69. 15:01:41 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  70. $ docker ps
  71. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  72. 1835dd183b75 debian:9.5 "sh -c 'apt-get -qy …" 43 minutes ago Up 43 minutes kube-node5
  73. 30b0af8d2924 debian:9.5 "sh -c 'apt-get -qy …" 43 minutes ago Up 43 minutes kube-node4
  74. 3e0d1510c62f debian:9.5 "sh -c 'apt-get -qy …" 43 minutes ago Up 43 minutes kube-node3
  75. 738993566f94 debian:9.5 "sh -c 'apt-get -qy …" 44 minutes ago Up 44 minutes kube-node2
  76. c581ef662ed2 debian:9.5 "sh -c 'apt-get -qy …" 44 minutes ago Up 44 minutes kube-node1
  77. $ docker exec kube-node1 kubectl get node
  78. NAME STATUS ROLES AGE VERSION
  79. kube-node1 Ready master,node 18m v1.12.1
  80. kube-node2 Ready master,node 17m v1.12.1
  81. kube-node3 Ready node 17m v1.12.1
  82. kube-node4 Ready node 17m v1.12.1
  83. kube-node5 Ready node 17m v1.12.1
  84. $ docker exec kube-node1 kubectl get pod --all-namespaces
  85. NAMESPACE NAME READY STATUS RESTARTS AGE
  86. default netchecker-agent-67489 1/1 Running 0 2m51s
  87. default netchecker-agent-6qq6s 1/1 Running 0 2m51s
  88. default netchecker-agent-fsw92 1/1 Running 0 2m51s
  89. default netchecker-agent-fw6tl 1/1 Running 0 2m51s
  90. default netchecker-agent-hostnet-8f2zb 1/1 Running 0 3m
  91. default netchecker-agent-hostnet-gq7ml 1/1 Running 0 3m
  92. default netchecker-agent-hostnet-jfkgv 1/1 Running 0 3m
  93. default netchecker-agent-hostnet-kwfwx 1/1 Running 0 3m
  94. default netchecker-agent-hostnet-r46nm 1/1 Running 0 3m
  95. default netchecker-agent-lxdrn 1/1 Running 0 2m51s
  96. default netchecker-server-864bd4c897-9vstl 1/1 Running 0 2m40s
  97. default sh-68fcc6db45-qf55h 1/1 Running 1 12m
  98. kube-system coredns-7598f59475-6vknq 1/1 Running 0 14m
  99. kube-system coredns-7598f59475-l5q5x 1/1 Running 0 14m
  100. kube-system kube-apiserver-kube-node1 1/1 Running 0 17m
  101. kube-system kube-apiserver-kube-node2 1/1 Running 0 18m
  102. kube-system kube-controller-manager-kube-node1 1/1 Running 0 18m
  103. kube-system kube-controller-manager-kube-node2 1/1 Running 0 18m
  104. kube-system kube-proxy-5xx9d 1/1 Running 0 17m
  105. kube-system kube-proxy-cdqq4 1/1 Running 0 17m
  106. kube-system kube-proxy-n64ls 1/1 Running 0 17m
  107. kube-system kube-proxy-pswmj 1/1 Running 0 18m
  108. kube-system kube-proxy-x89qw 1/1 Running 0 18m
  109. kube-system kube-scheduler-kube-node1 1/1 Running 4 17m
  110. kube-system kube-scheduler-kube-node2 1/1 Running 4 18m
  111. kube-system kubernetes-dashboard-5db4d9f45f-548rl 1/1 Running 0 14m
  112. kube-system nginx-proxy-kube-node3 1/1 Running 4 17m
  113. kube-system nginx-proxy-kube-node4 1/1 Running 4 17m
  114. kube-system nginx-proxy-kube-node5 1/1 Running 4 17m
  115. kube-system weave-net-42bfr 2/2 Running 0 16m
  116. kube-system weave-net-6gt8m 2/2 Running 0 16m
  117. kube-system weave-net-88nnc 2/2 Running 0 16m
  118. kube-system weave-net-shckr 2/2 Running 0 16m
  119. kube-system weave-net-xr46t 2/2 Running 0 16m
  120. $ docker exec kube-node1 curl -s http://localhost:31081/api/v1/connectivity_check
  121. {"Message":"All 10 pods successfully reported back to the server","Absent":null,"Outdated":null}
  122. ~~~
  123. ## Using ./run-test-distros.sh
  124. You can use `./run-test-distros.sh` to run a set of tests via DIND,
  125. and excerpt from this script, to get an idea:
  126. ~~~
  127. # The SPEC file(s) must have two arrays as e.g.
  128. # DISTROS=(debian centos)
  129. # EXTRAS=(
  130. # 'kube_network_plugin=calico'
  131. # 'kube_network_plugin=flannel'
  132. # 'kube_network_plugin=weave'
  133. # )
  134. # that will be tested in a "combinatory" way (e.g. from above there'll be
  135. # be 6 test runs), creating a sequenced <spec_filename>-nn.out with each output.
  136. #
  137. # Each $EXTRAS element will be whitespace split, and passed as --extra-vars
  138. # to main kubespray ansible-playbook run.
  139. ~~~
  140. See e.g. `test-some_distros-most_CNIs.env` and
  141. `test-some_distros-kube_router_combo.env` in particular for a richer
  142. set of CNI specific `--extra-vars` combo.