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.

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