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.

275 lines
8.2 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
9 years ago
9 years ago
9 years ago
  1. [![Build Status](https://travis-ci.org/ansibl8s/setup-kubernetes.svg)](https://travis-ci.org/ansibl8s/setup-kubernetes)
  2. kubernetes-ansible
  3. ========
  4. This project allows to
  5. - Install and configure a **Multi-Master/HA kubernetes** cluster.
  6. - Choose the **network plugin** to be used withini the cluster
  7. - A **set of roles** in order to install applications over the k8s cluster
  8. - A **flexible method** which helps to create new roles for apps.
  9. ### Requirements
  10. Tested on **Debian Wheezy/Jessie** and **Ubuntu** (14.10, 15.04, 15.10).
  11. Should work on **RedHat/Fedora/Centos** platforms (to be tested)
  12. * The target servers must have access to the Internet in order to pull docker imaqes.
  13. * The firewalls are not managed, you'll need to implement your own rules the way you used to.
  14. in order to avoid any issue during deployment you should **disable your firewall**
  15. * **Copy your ssh keys** to all the servers part of your inventory.
  16. * **Ansible v1.9.x/v2.x and python-netaddr**
  17. * Base knowledge on Ansible. Please refer to [Ansible documentation](http://www.ansible.com/how-ansible-works)
  18. ### Components
  19. * [kubernetes](https://github.com/kubernetes/kubernetes/releases) v1.1.3
  20. * [etcd](https://github.com/coreos/etcd/releases) v2.2.2
  21. * [calicoctl](https://github.com/projectcalico/calico-docker/releases) v0.13.0
  22. * [flanneld](https://github.com/coreos/flannel/releases) v0.5.5
  23. * [docker](https://www.docker.com/) v1.9.1
  24. Quickstart
  25. -------------------------
  26. The following steps will quickly setup a kubernetes cluster with default configuration.
  27. These defaults are good for tests purposes.
  28. Edit the inventory according to the number of servers
  29. ```
  30. [downloader]
  31. localhost ansible_connection=local ansible_python_interpreter=python2
  32. [kube-master]
  33. 10.115.99.31
  34. [etcd]
  35. 10.115.99.31
  36. 10.115.99.32
  37. 10.115.99.33
  38. [kube-node]
  39. 10.115.99.32
  40. 10.115.99.33
  41. [k8s-cluster:children]
  42. kube-node
  43. kube-master
  44. ```
  45. Run the playbook
  46. ```
  47. ansible-playbook -i inventory/inventory.cfg cluster.yml -u root
  48. ```
  49. You can jump directly to "*Available apps, installation procedure*"
  50. Ansible
  51. -------------------------
  52. ### Variables
  53. The main variables to change are located in the directory ```inventory/group_vars/all.yml```.
  54. ### Inventory
  55. Below is an example of an inventory.
  56. Note : The bgp vars local_as and peers are not mandatory if the var **'peer_with_router'** is set to false
  57. By default this variable is set to false and therefore all the nodes are configure in **'node-mesh'** mode.
  58. In node-mesh mode the nodes peers with all the nodes in order to exchange routes.
  59. ```
  60. [downloader]
  61. localhost ansible_connection=local ansible_python_interpreter=python2
  62. [kube-master]
  63. node1 ansible_ssh_host=10.99.0.26
  64. node2 ansible_ssh_host=10.99.0.27
  65. [etcd]
  66. node1 ansible_ssh_host=10.99.0.26
  67. node2 ansible_ssh_host=10.99.0.27
  68. node3 ansible_ssh_host=10.99.0.4
  69. [kube-node]
  70. node2 ansible_ssh_host=10.99.0.27
  71. node3 ansible_ssh_host=10.99.0.4
  72. node4 ansible_ssh_host=10.99.0.5
  73. node5 ansible_ssh_host=10.99.0.36
  74. node6 ansible_ssh_host=10.99.0.37
  75. [paris]
  76. node1 ansible_ssh_host=10.99.0.26
  77. node3 ansible_ssh_host=10.99.0.4 local_as=xxxxxxxx
  78. node4 ansible_ssh_host=10.99.0.5 local_as=xxxxxxxx
  79. [new-york]
  80. node2 ansible_ssh_host=10.99.0.27
  81. node5 ansible_ssh_host=10.99.0.36 local_as=xxxxxxxx
  82. node6 ansible_ssh_host=10.99.0.37 local_as=xxxxxxxx
  83. [k8s-cluster:children]
  84. kube-node
  85. kube-master
  86. ```
  87. ### Playbook
  88. ```
  89. ---
  90. - hosts: downloader
  91. sudo: no
  92. roles:
  93. - { role: download, tags: download }
  94. - hosts: k8s-cluster
  95. roles:
  96. - { role: kubernetes/preinstall, tags: preinstall }
  97. - { role: docker, tags: docker }
  98. - { role: kubernetes/node, tags: node }
  99. - { role: etcd, tags: etcd }
  100. - { role: dnsmasq, tags: dnsmasq }
  101. - { role: network_plugin, tags: ['calico', 'flannel', 'network'] }
  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 inventory/dev/inventory.cfg 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. * For safety reasons, you should have at least two master nodes and 3 etcd servers
  119. * Kube-proxy doesn't support multiple apiservers on startup ([Issue 18174](https://github.com/kubernetes/kubernetes/issues/18174)). An external loadbalancer needs to be configured.
  120. In order to do so, some variables have to be used '**loadbalancer_apiserver**' and '**apiserver_loadbalancer_domain_name**'
  121. ### Network Overlay
  122. You can choose between 2 network plugins. Only one must be chosen.
  123. * **flannel**: gre/vxlan (layer 2) networking. ([official docs](https://github.com/coreos/flannel))
  124. * **calico**: bgp (layer 3) networking. ([official docs](http://docs.projectcalico.org/en/0.13/))
  125. The choice is defined with the variable '**kube_network_plugin**'
  126. ### Expose a service
  127. There are several loadbalancing solutions.
  128. The one i found suitable for kubernetes are [Vulcand](http://vulcand.io/) and [Haproxy](http://www.haproxy.org/)
  129. My cluster is working with haproxy and kubernetes services are configured with the loadbalancing type '**nodePort**'.
  130. eg: each node opens the same tcp port and forwards the traffic to the target pod wherever it is located.
  131. Then Haproxy can be configured to request kubernetes's api in order to loadbalance on the proper tcp port on the nodes.
  132. Please refer to the proper kubernetes documentation on [Services](https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/user-guide/services.md)
  133. ### Check cluster status
  134. #### Kubernetes components
  135. * Check the status of the processes
  136. ```
  137. systemctl status kubelet
  138. ```
  139. * Check the logs
  140. ```
  141. journalctl -ae -u kubelet
  142. ```
  143. * Check the NAT rules
  144. ```
  145. iptables -nLv -t nat
  146. ```
  147. For the master nodes you'll have to see the docker logs for the apiserver
  148. ```
  149. docker logs [apiserver docker id]
  150. ```
  151. ### Available apps, installation procedure
  152. There are two ways of installing new apps
  153. #### Ansible galaxy
  154. Additionnal apps can be installed with ```ansible-galaxy```.
  155. ou'll need to edit the file '*requirements.yml*' in order to chose needed apps.
  156. The list of available apps are available [there](https://github.com/ansibl8s)
  157. For instance it is **strongly recommanded** to install a dns server which resolves kubernetes service names.
  158. In order to use this role you'll need the following entries in the file '*requirements.yml*'
  159. Please refer to the [k8s-kubedns readme](https://github.com/ansibl8s/k8s-kubedns) for additionnal info.
  160. ```
  161. - src: https://github.com/ansibl8s/k8s-common.git
  162. path: roles/apps
  163. # version: v1.0
  164. - src: https://github.com/ansibl8s/k8s-kubedns.git
  165. path: roles/apps
  166. # version: v1.0
  167. ```
  168. **Note**: the role common is required by all the apps and provides the tasks and libraries needed.
  169. And empty the apps directory
  170. ```
  171. rm -rf roles/apps/*
  172. ```
  173. Then download the roles with ansible-galaxy
  174. ```
  175. ansible-galaxy install -r requirements.yml
  176. ```
  177. Finally update the playbook ```apps.yml``` with the chosen roles, and run it
  178. ```
  179. ...
  180. - hosts: kube-master
  181. roles:
  182. - { role: apps/k8s-kubedns, tags: ['kubedns', 'apps'] }
  183. ...
  184. ```
  185. ```
  186. ansible-playbook -i inventory/inventory.cfg apps.yml -u root
  187. ```
  188. #### Git submodules
  189. Alternatively the roles can be installed as git submodules.
  190. That way is easier if you want to do some changes and commit them.
  191. #### Calico networking
  192. Check if the calico-node container is running
  193. ```
  194. docker ps | grep calico
  195. ```
  196. The **calicoctl** command allows to check the status of the network workloads.
  197. * Check the status of Calico nodes
  198. ```
  199. calicoctl status
  200. ```
  201. * Show the configured network subnet for containers
  202. ```
  203. calicoctl pool show
  204. ```
  205. * Show the workloads (ip addresses of containers and their located)
  206. ```
  207. calicoctl endpoint show --detail
  208. ```
  209. #### Flannel networking
  210. Congrats ! now you can walk through [kubernetes basics](http://kubernetes.io/v1.1/basicstutorials.html)