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.

260 lines
7.7 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
  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. Ansible v1.9.x
  10. ### Components
  11. * [kubernetes](https://github.com/kubernetes/kubernetes/releases) v1.0.6
  12. * [etcd](https://github.com/coreos/etcd/releases) v2.2.0
  13. * [calicoctl](https://github.com/projectcalico/calico-docker/releases) v0.5.1
  14. * [flanneld](https://github.com/coreos/flannel/releases) v0.5.3
  15. * [docker](https://www.docker.com/) v1.8.3
  16. Ansible
  17. -------------------------
  18. ### Download binaries
  19. A role allows to download required binaries which will be stored in a directory defined by the variable
  20. **'local_release_dir'** (by default /tmp).
  21. Please ensure that you have enough disk space there (about **1G**).
  22. **Note**: Whenever you'll need to change the version of a software, you'll have to erase the content of this directory.
  23. ### Variables
  24. The main variables to change are located in the directory ```environments/[env_name]/group_vars/k8s-cluster.yml```.
  25. ### Inventory
  26. Below is an example of an inventory.
  27. Note : The bgp vars local_as and peers are not mandatory if the var "peer_with_router" is set to false
  28. By default this variable is set to false and therefore all the nodes are configure in "node-mesh" mode.
  29. In node-mesh mode the nodes peers with all the nodes in order to exchange routes.
  30. ```
  31. [downloader]
  32. 10.99.0.26
  33. [kube-master]
  34. # NB : the br_addr must be in the {{ calico_pool }} subnet
  35. # it will assign a /24 subnet per node
  36. 10.99.0.26 br_addr=10.99.64.1
  37. [etcd]
  38. 10.99.0.26
  39. [kube-node]
  40. 10.99.0.4
  41. 10.99.0.5
  42. 10.99.0.6
  43. 10.99.0.36
  44. 10.99.0.37
  45. [itx2]
  46. 10.99.0.26 br_addr=10.99.16.1
  47. 10.99.0.4 br_addr=10.99.65.1 local_as=xxxxxxxx
  48. 10.99.0.5 br_addr=10.99.66.1 local_as=xxxxxxxx
  49. 10.99.0.6 br_addr=10.99.69.1 local_as=xxxxxxxx
  50. [rmv]
  51. 10.99.0.36 br_addr=10.99.67.1 local_as=xxxxxxxx
  52. 10.99.0.37 br_addr=10.99.68.1 local_as=xxxxxxxx
  53. [k8s-cluster:children]
  54. kube-node
  55. kube-master
  56. [itx2:vars]
  57. peers=[{"router_id": "10.99.0.2", "as": "65xxx"}, {"router_id": "10.99.0.3", "as": "65xxx"}]
  58. [rmv:vars]
  59. peers=[{"router_id": "10.99.0.34", "as": "65xxx"}, {"router_id": "10.99.0.35", "as": "65xxx"}]
  60. ```
  61. ### Playbook
  62. ```
  63. ---
  64. - hosts: downloader
  65. sudo: no
  66. roles:
  67. - { role: download, tags: download }
  68. - hosts: k8s-cluster
  69. roles:
  70. - { role: etcd, tags: etcd }
  71. - { role: docker, tags: docker }
  72. - { role: network_plugin, tags: ['calico', 'flannel', 'network'] }
  73. - { role: dnsmasq, tags: dnsmasq }
  74. - hosts: kube-master
  75. roles:
  76. - { role: kubernetes/master, tags: master }
  77. - hosts: kube-node
  78. roles:
  79. - { role: kubernetes/node, tags: node }
  80. - hosts: kube-master
  81. roles:
  82. - { role: apps/k8s-kubedns, tags: ['kubedns', 'apps'] }
  83. - { role: apps/k8s-fabric8, tags: ['fabric8', 'apps'] }
  84. ```
  85. ### Run
  86. It is possible to define variables for different environments.
  87. For instance, in order to deploy the cluster on 'dev' environment run the following command.
  88. ```
  89. ansible-playbook -i environments/dev/inventory cluster.yml -u root
  90. ```
  91. Kubernetes
  92. -------------------------
  93. ### Network Overlay
  94. You can choose between 2 network plugins. Only one must be chosen.
  95. * **flannel**: gre/vxlan (layer 2) networking. ([official docs]('https://github.com/coreos/flannel'))
  96. * **calico**: bgp (layer 3) networking. ([official docs]('http://docs.projectcalico.org/en/0.13/'))
  97. The choice is defined with the variable '**kube_network_plugin**'
  98. ### Expose a service
  99. There are several loadbalancing solutions.
  100. The ones i found suitable for kubernetes are [Vulcand]('http://vulcand.io/') and [Haproxy]('http://www.haproxy.org/')
  101. My cluster is working with haproxy and kubernetes services are configured with the loadbalancing type '**nodePort**'.
  102. eg: each node opens the same tcp port and forwards the traffic to the target pod wherever it is located.
  103. Then Haproxy can be configured to request kubernetes's api in order to loadbalance on the proper tcp port on the nodes.
  104. Please refer to the proper kubernetes documentation on [Services]('https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/user-guide/services.md')
  105. ### Check cluster status
  106. #### Kubernetes components
  107. Master processes : kube-apiserver, kube-scheduler, kube-controller, kube-proxy
  108. Nodes processes : kubelet, kube-proxy, [calico-node|flanneld]
  109. * Check the status of the processes
  110. ```
  111. systemctl status [process_name]
  112. ```
  113. * Check the logs
  114. ```
  115. journalctl -ae -u [process_name]
  116. ```
  117. * Check the NAT rules
  118. ```
  119. iptables -nLv -t nat
  120. ```
  121. ### Available apps, installation procedure
  122. There are two ways of installing new apps
  123. #### Ansible galaxy
  124. Additionnal apps can be installed with ```ansible-galaxy```.
  125. you'll need to edit the file '*requirements.yml*' in order to chose needed apps.
  126. The list of available apps are available [there](https://github.com/ansibl8s)
  127. For instance if you will probably want to install a [dns server](https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns) as it is **strongly recommanded**.
  128. In order to use this role you'll need the following entries in the file '*requirements.yml*'
  129. ```
  130. - src: https://github.com/ansibl8s/k8s-common.git
  131. path: roles/apps
  132. # version: v1.0
  133. - src: https://github.com/ansibl8s/k8s-kubedns.git
  134. path: roles/apps
  135. # version: v1.0
  136. ```
  137. **Note**: the role common is required by all the apps and provides the tasks and libraries needed.
  138. And empty the apps directory
  139. ```
  140. rm -rf roles/apps/*
  141. ```
  142. Then download the roles with ansible-galaxy
  143. ```
  144. ansible-galaxy install -r requirements.yml
  145. ```
  146. #### Git submodules
  147. Alternatively the roles can be installed as git submodules.
  148. That way is easier if you want to do some changes and commit them.
  149. You can list available submodules with the following command:
  150. ```
  151. grep path .gitmodules | sed 's/.*= //'
  152. ```
  153. For instance if you will probably want to install a [dns server](https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns) as it is **strongly recommanded**.
  154. In order to use this role you'll need to follow these steps
  155. ```
  156. git submodule init roles/apps/k8s-common roles/apps/k8s-kubedns
  157. git submodule update
  158. ```
  159. Finally update your playbook with the chosen role, and run it
  160. ```
  161. ...
  162. - hosts: kube-master
  163. roles:
  164. - { role: apps/k8s-kubedns, tags: ['kubedns', 'apps'] }
  165. ...
  166. ```
  167. Please refer to the [k8s-kubdns readme](https://github.com/ansibl8s/k8s-kubedns) for additionnal info.
  168. #### Calico networking
  169. Check if the calico-node container is running
  170. ```
  171. docker ps | grep calico
  172. ```
  173. The **calicoctl** command allows to check the status of the network workloads.
  174. * Check the status of Calico nodes
  175. ```
  176. calicoctl status
  177. ```
  178. * Show the configured network subnet for containers
  179. ```
  180. calicoctl pool show
  181. ```
  182. * Show the workloads (ip addresses of containers and their located)
  183. ```
  184. calicoctl endpoint show --detail
  185. ```
  186. #### Flannel networking
  187. Congrats ! now you can walk through [kubernetes basics](http://kubernetes.io/v1.0/basicstutorials.html)
  188. Known issues
  189. -------------
  190. ### Node reboot and Calico
  191. There is a major issue with calico-kubernetes version 0.5.1 and kubernetes prior to 1.1 :
  192. After host reboot, the pods networking are not configured again, they are started without any network configuration.
  193. This issue will be fixed when kubernetes 1.1 will be released as described in this [issue](https://github.com/projectcalico/calico-kubernetes/issues/34)
  194. ### Monitoring addon
  195. Until now i didn't managed to get the monitoring addon working.
  196. ### Apiserver listen on secure port only
  197. Currently the api-server listens on both secure and insecure ports.
  198. The insecure port is mainly used for calico.
  199. Will be fixed soon.