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.

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