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.

288 lines
8.0 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. kubernetes-ansible
  2. ========
  3. Install and configure a kubernetes cluster including network plugin.
  4. ### Requirements
  5. Tested on **Debian Jessie** and **Ubuntu** (14.10, 15.04, 15.10).
  6. * The target servers must have access to the Internet in order to pull docker imaqes.
  7. * The firewalls are not managed, you'll need to implement your own rules the way you used to.
  8. Ansible v1.9.x
  9. ### Components
  10. * [kubernetes](https://github.com/kubernetes/kubernetes/releases) v1.1.3
  11. * [etcd](https://github.com/coreos/etcd/releases) v2.2.2
  12. * [calicoctl](https://github.com/projectcalico/calico-docker/releases) v0.13.0
  13. * [flanneld](https://github.com/coreos/flannel/releases) v0.5.5
  14. * [docker](https://www.docker.com/) v1.9.1
  15. Quickstart
  16. -------------------------
  17. The following steps will quickly setup a kubernetes cluster with default configuration.
  18. These defaults are good for tests purposes.
  19. Edit the inventory according to the number of servers
  20. ```
  21. [downloader]
  22. 10.115.99.1
  23. [kube-master]
  24. 10.115.99.31
  25. [etcd]
  26. 10.115.99.31
  27. 10.115.99.32
  28. 10.115.99.33
  29. [kube-node]
  30. 10.115.99.32
  31. 10.115.99.33
  32. [k8s-cluster:children]
  33. kube-node
  34. kube-master
  35. ```
  36. Run the playbook
  37. ```
  38. ansible-playbook -i inventory/inventory.cfg cluster.yml -u root
  39. ```
  40. You can jump directly to "*Available apps, installation procedure*"
  41. Ansible
  42. -------------------------
  43. ### Download binaries
  44. A role allows to download required binaries. They will be stored in a directory defined by the variable
  45. **'local_release_dir'** (by default /tmp).
  46. Please ensure that you have enough disk space there (about **300M**).
  47. **Note**: Whenever you'll need to change the version of a software, you'll have to erase the content of this directory.
  48. ### Variables
  49. The main variables to change are located in the directory ```inventory/group_vars/all.yml```.
  50. ### Inventory
  51. Below is an example of an inventory.
  52. Note : The bgp vars local_as and peers are not mandatory if the var **'peer_with_router'** is set to false
  53. By default this variable is set to false and therefore all the nodes are configure in **'node-mesh'** mode.
  54. In node-mesh mode the nodes peers with all the nodes in order to exchange routes.
  55. ```
  56. [downloader]
  57. node1 ansible_ssh_host=10.99.0.26
  58. [kube-master]
  59. node1 ansible_ssh_host=10.99.0.26
  60. node2 ansible_ssh_host=10.99.0.27
  61. [etcd]
  62. node1 ansible_ssh_host=10.99.0.26
  63. node2 ansible_ssh_host=10.99.0.27
  64. node3 ansible_ssh_host=10.99.0.4
  65. [kube-node]
  66. node2 ansible_ssh_host=10.99.0.27
  67. node3 ansible_ssh_host=10.99.0.4
  68. node4 ansible_ssh_host=10.99.0.5
  69. node5 ansible_ssh_host=10.99.0.36
  70. node6 ansible_ssh_host=10.99.0.37
  71. [paris]
  72. node1 ansible_ssh_host=10.99.0.26
  73. node3 ansible_ssh_host=10.99.0.4 local_as=xxxxxxxx
  74. node4 ansible_ssh_host=10.99.0.5 local_as=xxxxxxxx
  75. [new-york]
  76. node2 ansible_ssh_host=10.99.0.27
  77. node5 ansible_ssh_host=10.99.0.36 local_as=xxxxxxxx
  78. node6 ansible_ssh_host=10.99.0.37 local_as=xxxxxxxx
  79. [k8s-cluster:children]
  80. kube-node
  81. kube-master
  82. ```
  83. ### Playbook
  84. ```
  85. ---
  86. - hosts: downloader
  87. sudo: no
  88. roles:
  89. - { role: download, tags: download }
  90. - hosts: k8s-cluster
  91. roles:
  92. - { role: etcd, tags: etcd }
  93. - { role: docker, tags: docker }
  94. - { role: dnsmasq, tags: dnsmasq }
  95. - { role: network_plugin, tags: ['calico', 'flannel', 'network'] }
  96. - hosts: kube-master
  97. roles:
  98. - { role: kubernetes/master, tags: master }
  99. - hosts: kube-node
  100. roles:
  101. - { role: kubernetes/node, tags: node }
  102. ```
  103. ### Run
  104. It is possible to define variables for different environments.
  105. For instance, in order to deploy the cluster on 'dev' environment run the following command.
  106. ```
  107. ansible-playbook -i inventory/dev/inventory.cfg cluster.yml -u root
  108. ```
  109. Kubernetes
  110. -------------------------
  111. ### Multi master notes
  112. * You can choose where to install the master components. If you want your master node to act both as master (api,scheduler,controller) and node (e.g. accept workloads, create pods ...),
  113. the server address has to be present on both groups 'kube-master' and 'kube-node'.
  114. * Almost all kubernetes components are running into pods except *kubelet*. These pods are managed by kubelet which ensure they're always running
  115. * For safety reasons, you should have at least two master nodes and 3 etcd servers
  116. * Kube-proxy doesn't support multiple apiservers on startup ([Issue 18174](https://github.com/kubernetes/kubernetes/issues/18174)). An external loadbalancer needs to be configured.
  117. In order to do so, some variables have to be used '**loadbalancer_apiserver**' and '**apiserver_loadbalancer_domain_name**'
  118. ### Network Overlay
  119. You can choose between 2 network plugins. Only one must be chosen.
  120. * **flannel**: gre/vxlan (layer 2) networking. ([official docs](https://github.com/coreos/flannel))
  121. * **calico**: bgp (layer 3) networking. ([official docs](http://docs.projectcalico.org/en/0.13/))
  122. The choice is defined with the variable '**kube_network_plugin**'
  123. ### Expose a service
  124. There are several loadbalancing solutions.
  125. The one i found suitable for kubernetes are [Vulcand](http://vulcand.io/) and [Haproxy](http://www.haproxy.org/)
  126. My cluster is working with haproxy and kubernetes services are configured with the loadbalancing type '**nodePort**'.
  127. eg: each node opens the same tcp port and forwards the traffic to the target pod wherever it is located.
  128. Then Haproxy can be configured to request kubernetes's api in order to loadbalance on the proper tcp port on the nodes.
  129. Please refer to the proper kubernetes documentation on [Services](https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/user-guide/services.md)
  130. ### Check cluster status
  131. #### Kubernetes components
  132. * Check the status of the processes
  133. ```
  134. systemctl status kubelet
  135. ```
  136. * Check the logs
  137. ```
  138. journalctl -ae -u kubelet
  139. ```
  140. * Check the NAT rules
  141. ```
  142. iptables -nLv -t nat
  143. ```
  144. For the master nodes you'll have to see the docker logs for the apiserver
  145. ```
  146. docker logs [apiserver docker id]
  147. ```
  148. ### Available apps, installation procedure
  149. There are two ways of installing new apps
  150. #### Ansible galaxy
  151. Additionnal apps can be installed with ```ansible-galaxy```.
  152. ou'll need to edit the file '*requirements.yml*' in order to chose needed apps.
  153. The list of available apps are available [there](https://github.com/ansibl8s)
  154. For instance it is **strongly recommanded** to install a dns server which resolves kubernetes service names.
  155. In order to use this role you'll need the following entries in the file '*requirements.yml*'
  156. Please refer to the [k8s-kubedns readme](https://github.com/ansibl8s/k8s-kubedns) for additionnal info.
  157. ```
  158. - src: https://github.com/ansibl8s/k8s-common.git
  159. path: roles/apps
  160. # version: v1.0
  161. - src: https://github.com/ansibl8s/k8s-kubedns.git
  162. path: roles/apps
  163. # version: v1.0
  164. ```
  165. **Note**: the role common is required by all the apps and provides the tasks and libraries needed.
  166. And empty the apps directory
  167. ```
  168. rm -rf roles/apps/*
  169. ```
  170. Then download the roles with ansible-galaxy
  171. ```
  172. ansible-galaxy install -r requirements.yml
  173. ```
  174. #### Git submodules
  175. Alternatively the roles can be installed as git submodules.
  176. That way is easier if you want to do some changes and commit them.
  177. You can list available submodules with the following command:
  178. ```
  179. grep path .gitmodules | sed 's/.*= //'
  180. ```
  181. In order to install the dns addon you'll need to follow these steps
  182. ```
  183. git submodule init roles/apps/k8s-common roles/apps/k8s-kubedns
  184. git submodule update
  185. ```
  186. Finally update the playbook ```apps.yml``` with the chosen roles, and run it
  187. ```
  188. ...
  189. - hosts: kube-master
  190. roles:
  191. - { role: apps/k8s-kubedns, tags: ['kubedns', 'apps'] }
  192. ...
  193. ```
  194. ```
  195. ansible-playbook -i environments/dev/inventory apps.yml -u root
  196. ```
  197. #### Calico networking
  198. Check if the calico-node container is running
  199. ```
  200. docker ps | grep calico
  201. ```
  202. The **calicoctl** command allows to check the status of the network workloads.
  203. * Check the status of Calico nodes
  204. ```
  205. calicoctl status
  206. ```
  207. * Show the configured network subnet for containers
  208. ```
  209. calicoctl pool show
  210. ```
  211. * Show the workloads (ip addresses of containers and their located)
  212. ```
  213. calicoctl endpoint show --detail
  214. ```
  215. #### Flannel networking
  216. Congrats ! now you can walk through [kubernetes basics](http://kubernetes.io/v1.1/basicstutorials.html)