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.

242 lines
6.6 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
  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.1.2
  12. * [etcd](https://github.com/coreos/etcd/releases) v2.2.2
  13. * [calicoctl](https://github.com/projectcalico/calico-docker/releases) v0.5.1
  14. * [flanneld](https://github.com/coreos/flannel/releases) v0.5.5
  15. * [docker](https://www.docker.com/) v1.8.3
  16. Ansible
  17. -------------------------
  18. ### Download binaries
  19. A role allows to download required binaries. They 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. 10.99.0.26
  35. [etcd]
  36. 10.99.0.26
  37. [kube-node]
  38. 10.99.0.4
  39. 10.99.0.5
  40. 10.99.0.6
  41. 10.99.0.36
  42. 10.99.0.37
  43. [itx2]
  44. 10.99.0.26
  45. 10.99.0.4 local_as=xxxxxxxx
  46. 10.99.0.5 local_as=xxxxxxxx
  47. 10.99.0.6 local_as=xxxxxxxx
  48. [rmv]
  49. 10.99.0.36 local_as=xxxxxxxx
  50. 10.99.0.37 local_as=xxxxxxxx
  51. [k8s-cluster:children]
  52. kube-node
  53. kube-master
  54. [itx2:vars]
  55. peers=[{"router_id": "10.99.0.2", "as": "65xxx"}, {"router_id": "10.99.0.3", "as": "65xxx"}]
  56. [rmv:vars]
  57. peers=[{"router_id": "10.99.0.34", "as": "65xxx"}, {"router_id": "10.99.0.35", "as": "65xxx"}]
  58. ```
  59. ### Playbook
  60. ```
  61. ---
  62. - hosts: downloader
  63. sudo: no
  64. roles:
  65. - { role: download, tags: download }
  66. - hosts: k8s-cluster
  67. roles:
  68. - { role: etcd, tags: etcd }
  69. - { role: docker, tags: docker }
  70. - { role: network_plugin, tags: ['calico', 'flannel', 'network'] }
  71. - { role: dnsmasq, tags: dnsmasq }
  72. - hosts: kube-master
  73. roles:
  74. - { role: kubernetes/master, tags: master }
  75. - hosts: kube-node
  76. roles:
  77. - { role: kubernetes/node, tags: node }
  78. ```
  79. ### Run
  80. It is possible to define variables for different environments.
  81. For instance, in order to deploy the cluster on 'dev' environment run the following command.
  82. ```
  83. ansible-playbook -i environments/dev/inventory cluster.yml -u root
  84. ```
  85. Kubernetes
  86. -------------------------
  87. ### Network Overlay
  88. You can choose between 2 network plugins. Only one must be chosen.
  89. * **flannel**: gre/vxlan (layer 2) networking. ([official docs]('https://github.com/coreos/flannel'))
  90. * **calico**: bgp (layer 3) networking. ([official docs]('http://docs.projectcalico.org/en/0.13/'))
  91. The choice is defined with the variable '**kube_network_plugin**'
  92. ### Expose a service
  93. There are several loadbalancing solutions.
  94. The ones i found suitable for kubernetes are [Vulcand]('http://vulcand.io/') and [Haproxy]('http://www.haproxy.org/')
  95. My cluster is working with haproxy and kubernetes services are configured with the loadbalancing type '**nodePort**'.
  96. eg: each node opens the same tcp port and forwards the traffic to the target pod wherever it is located.
  97. Then Haproxy can be configured to request kubernetes's api in order to loadbalance on the proper tcp port on the nodes.
  98. Please refer to the proper kubernetes documentation on [Services]('https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/user-guide/services.md')
  99. ### Check cluster status
  100. #### Kubernetes components
  101. Master processes : kube-apiserver, kube-scheduler, kube-controller, kube-proxy
  102. Nodes processes : kubelet, kube-proxy, [calico-node|flanneld]
  103. * Check the status of the processes
  104. ```
  105. systemctl status [process_name]
  106. ```
  107. * Check the logs
  108. ```
  109. journalctl -ae -u [process_name]
  110. ```
  111. * Check the NAT rules
  112. ```
  113. iptables -nLv -t nat
  114. ```
  115. ### Available apps, installation procedure
  116. There are two ways of installing new apps
  117. #### Ansible galaxy
  118. Additionnal apps can be installed with ```ansible-galaxy```.
  119. you'll need to edit the file '*requirements.yml*' in order to chose needed apps.
  120. The list of available apps are available [there](https://github.com/ansibl8s)
  121. For instance it is **strongly recommanded** to install a dns server which resolves kubernetes service names.
  122. In order to use this role you'll need the following entries in the file '*requirements.yml*'
  123. Please refer to the [k8s-kubdns readme](https://github.com/ansibl8s/k8s-kubedns) for additionnal info.
  124. ```
  125. - src: https://github.com/ansibl8s/k8s-common.git
  126. path: roles/apps
  127. # version: v1.0
  128. - src: https://github.com/ansibl8s/k8s-kubedns.git
  129. path: roles/apps
  130. # version: v1.0
  131. ```
  132. **Note**: the role common is required by all the apps and provides the tasks and libraries needed.
  133. And empty the apps directory
  134. ```
  135. rm -rf roles/apps/*
  136. ```
  137. Then download the roles with ansible-galaxy
  138. ```
  139. ansible-galaxy install -r requirements.yml
  140. ```
  141. #### Git submodules
  142. Alternatively the roles can be installed as git submodules.
  143. That way is easier if you want to do some changes and commit them.
  144. You can list available submodules with the following command:
  145. ```
  146. grep path .gitmodules | sed 's/.*= //'
  147. ```
  148. In order to install the dns addon you'll need to follow these steps
  149. ```
  150. git submodule init roles/apps/k8s-common roles/apps/k8s-kubedns
  151. git submodule update
  152. ```
  153. Finally update the playbook ```apps.yml``` with the chosen roles, and run it
  154. ```
  155. ...
  156. - hosts: kube-master
  157. roles:
  158. - { role: apps/k8s-kubedns, tags: ['kubedns', 'apps'] }
  159. ...
  160. ```
  161. ```
  162. ansible-playbook -i environments/dev/inventory apps.yml -u root
  163. ```
  164. #### Calico networking
  165. Check if the calico-node container is running
  166. ```
  167. docker ps | grep calico
  168. ```
  169. The **calicoctl** command allows to check the status of the network workloads.
  170. * Check the status of Calico nodes
  171. ```
  172. calicoctl status
  173. ```
  174. * Show the configured network subnet for containers
  175. ```
  176. calicoctl pool show
  177. ```
  178. * Show the workloads (ip addresses of containers and their located)
  179. ```
  180. calicoctl endpoint show --detail
  181. ```
  182. #### Flannel networking
  183. Congrats ! now you can walk through [kubernetes basics](http://kubernetes.io/v1.1/basicstutorials.html)