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.

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