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.

286 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/test/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 **300M**).
  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. ```
  85. ### Playbook
  86. ```
  87. ---
  88. - hosts: downloader
  89. sudo: no
  90. roles:
  91. - { role: download, tags: download }
  92. - hosts: k8s-cluster
  93. roles:
  94. - { role: etcd, tags: etcd }
  95. - { role: docker, tags: docker }
  96. - { role: dnsmasq, tags: dnsmasq }
  97. - { role: network_plugin, tags: ['calico', 'flannel', 'network'] }
  98. - hosts: kube-master
  99. roles:
  100. - { role: kubernetes/master, tags: master }
  101. - hosts: kube-node
  102. roles:
  103. - { role: kubernetes/node, tags: node }
  104. ```
  105. ### Run
  106. It is possible to define variables for different environments.
  107. For instance, in order to deploy the cluster on 'dev' environment run the following command.
  108. ```
  109. ansible-playbook -i environments/dev/inventory cluster.yml -u root
  110. ```
  111. Kubernetes
  112. -------------------------
  113. ### Multi master notes
  114. * 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 ...),
  115. the server address has to be present on both groups 'kube-master' and 'kube-node'.
  116. * Almost all kubernetes components are running into pods except *kubelet*. These pods are managed by kubelet which ensure they're always running
  117. * One etcd cluster member per node will be configured. For safety reasons, you should have at least two master nodes.
  118. * Kube-proxy doesn't support multiple apiservers on startup ([#18174]('https://github.com/kubernetes/kubernetes/issues/18174')). An external loadbalancer needs to be configured.
  119. In order to do so, some variables have to be used '**loadbalancer_apiserver**' and '**apiserver_loadbalancer_domain_name**'
  120. ### Network Overlay
  121. You can choose between 2 network plugins. Only one must be chosen.
  122. * **flannel**: gre/vxlan (layer 2) networking. ([official docs]('https://github.com/coreos/flannel'))
  123. * **calico**: bgp (layer 3) networking. ([official docs]('http://docs.projectcalico.org/en/0.13/'))
  124. The choice is defined with the variable '**kube_network_plugin**'
  125. ### Expose a service
  126. There are several loadbalancing solutions.
  127. The ones i found suitable for kubernetes are [Vulcand]('http://vulcand.io/') and [Haproxy]('http://www.haproxy.org/')
  128. My cluster is working with haproxy and kubernetes services are configured with the loadbalancing type '**nodePort**'.
  129. eg: each node opens the same tcp port and forwards the traffic to the target pod wherever it is located.
  130. Then Haproxy can be configured to request kubernetes's api in order to loadbalance on the proper tcp port on the nodes.
  131. Please refer to the proper kubernetes documentation on [Services]('https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/user-guide/services.md')
  132. ### Check cluster status
  133. #### Kubernetes components
  134. Master processes : kube-apiserver, kube-scheduler, kube-controller, kube-proxy
  135. Nodes processes : kubelet, kube-proxy, [calico-node|flanneld]
  136. * Check the status of the processes
  137. ```
  138. systemctl status [process_name]
  139. ```
  140. * Check the logs
  141. ```
  142. journalctl -ae -u [process_name]
  143. ```
  144. * Check the NAT rules
  145. ```
  146. iptables -nLv -t nat
  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-kubdns 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)