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.

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