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.

274 lines
8.1 KiB

8 years ago
8 years ago
9 years ago
8 years ago
8 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
8 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
8 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
8 years ago
9 years ago
8 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. ### Components
  18. * [kubernetes](https://github.com/kubernetes/kubernetes/releases) v1.1.3
  19. * [etcd](https://github.com/coreos/etcd/releases) v2.2.2
  20. * [calicoctl](https://github.com/projectcalico/calico-docker/releases) v0.13.0
  21. * [flanneld](https://github.com/coreos/flannel/releases) v0.5.5
  22. * [docker](https://www.docker.com/) v1.9.1
  23. Quickstart
  24. -------------------------
  25. The following steps will quickly setup a kubernetes cluster with default configuration.
  26. These defaults are good for tests purposes.
  27. Edit the inventory according to the number of servers
  28. ```
  29. [downloader]
  30. localhost ansible_connection=local ansible_python_interpreter=python2
  31. [kube-master]
  32. 10.115.99.31
  33. [etcd]
  34. 10.115.99.31
  35. 10.115.99.32
  36. 10.115.99.33
  37. [kube-node]
  38. 10.115.99.32
  39. 10.115.99.33
  40. [k8s-cluster:children]
  41. kube-node
  42. kube-master
  43. ```
  44. Run the playbook
  45. ```
  46. ansible-playbook -i inventory/inventory.cfg cluster.yml -u root
  47. ```
  48. You can jump directly to "*Available apps, installation procedure*"
  49. Ansible
  50. -------------------------
  51. ### Variables
  52. The main variables to change are located in the directory ```inventory/group_vars/all.yml```.
  53. ### Inventory
  54. Below is an example of an inventory.
  55. Note : The bgp vars local_as and peers are not mandatory if the var **'peer_with_router'** is set to false
  56. By default this variable is set to false and therefore all the nodes are configure in **'node-mesh'** mode.
  57. In node-mesh mode the nodes peers with all the nodes in order to exchange routes.
  58. ```
  59. [downloader]
  60. localhost ansible_connection=local ansible_python_interpreter=python2
  61. [kube-master]
  62. node1 ansible_ssh_host=10.99.0.26
  63. node2 ansible_ssh_host=10.99.0.27
  64. [etcd]
  65. node1 ansible_ssh_host=10.99.0.26
  66. node2 ansible_ssh_host=10.99.0.27
  67. node3 ansible_ssh_host=10.99.0.4
  68. [kube-node]
  69. node2 ansible_ssh_host=10.99.0.27
  70. node3 ansible_ssh_host=10.99.0.4
  71. node4 ansible_ssh_host=10.99.0.5
  72. node5 ansible_ssh_host=10.99.0.36
  73. node6 ansible_ssh_host=10.99.0.37
  74. [paris]
  75. node1 ansible_ssh_host=10.99.0.26
  76. node3 ansible_ssh_host=10.99.0.4 local_as=xxxxxxxx
  77. node4 ansible_ssh_host=10.99.0.5 local_as=xxxxxxxx
  78. [new-york]
  79. node2 ansible_ssh_host=10.99.0.27
  80. node5 ansible_ssh_host=10.99.0.36 local_as=xxxxxxxx
  81. node6 ansible_ssh_host=10.99.0.37 local_as=xxxxxxxx
  82. [k8s-cluster:children]
  83. kube-node
  84. kube-master
  85. ```
  86. ### Playbook
  87. ```
  88. ---
  89. - hosts: downloader
  90. sudo: no
  91. roles:
  92. - { role: download, tags: download }
  93. - hosts: k8s-cluster
  94. roles:
  95. - { role: kubernetes/preinstall, tags: preinstall }
  96. - { role: docker, tags: docker }
  97. - { role: kubernetes/node, tags: node }
  98. - { role: etcd, tags: etcd }
  99. - { role: dnsmasq, tags: dnsmasq }
  100. - { role: network_plugin, tags: ['calico', 'flannel', 'network'] }
  101. - hosts: kube-master
  102. roles:
  103. - { role: kubernetes/master, tags: master }
  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 inventory/dev/inventory.cfg 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. * For safety reasons, you should have at least two master nodes and 3 etcd servers
  118. * 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.
  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 one 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. * Check the status of the processes
  135. ```
  136. systemctl status kubelet
  137. ```
  138. * Check the logs
  139. ```
  140. journalctl -ae -u kubelet
  141. ```
  142. * Check the NAT rules
  143. ```
  144. iptables -nLv -t nat
  145. ```
  146. For the master nodes you'll have to see the docker logs for the apiserver
  147. ```
  148. docker logs [apiserver docker id]
  149. ```
  150. ### Available apps, installation procedure
  151. There are two ways of installing new apps
  152. #### Ansible galaxy
  153. Additionnal apps can be installed with ```ansible-galaxy```.
  154. ou'll need to edit the file '*requirements.yml*' in order to chose needed apps.
  155. The list of available apps are available [there](https://github.com/ansibl8s)
  156. For instance it is **strongly recommanded** to install a dns server which resolves kubernetes service names.
  157. In order to use this role you'll need the following entries in the file '*requirements.yml*'
  158. Please refer to the [k8s-kubedns readme](https://github.com/ansibl8s/k8s-kubedns) for additionnal info.
  159. ```
  160. - src: https://github.com/ansibl8s/k8s-common.git
  161. path: roles/apps
  162. # version: v1.0
  163. - src: https://github.com/ansibl8s/k8s-kubedns.git
  164. path: roles/apps
  165. # version: v1.0
  166. ```
  167. **Note**: the role common is required by all the apps and provides the tasks and libraries needed.
  168. And empty the apps directory
  169. ```
  170. rm -rf roles/apps/*
  171. ```
  172. Then download the roles with ansible-galaxy
  173. ```
  174. ansible-galaxy install -r requirements.yml
  175. ```
  176. Finally update the playbook ```apps.yml``` with the chosen roles, and run it
  177. ```
  178. ...
  179. - hosts: kube-master
  180. roles:
  181. - { role: apps/k8s-kubedns, tags: ['kubedns', 'apps'] }
  182. ...
  183. ```
  184. ```
  185. ansible-playbook -i inventory/inventory.cfg apps.yml -u root
  186. ```
  187. #### Git submodules
  188. Alternatively the roles can be installed as git submodules.
  189. That way is easier if you want to do some changes and commit them.
  190. #### Calico networking
  191. Check if the calico-node container is running
  192. ```
  193. docker ps | grep calico
  194. ```
  195. The **calicoctl** command allows to check the status of the network workloads.
  196. * Check the status of Calico nodes
  197. ```
  198. calicoctl status
  199. ```
  200. * Show the configured network subnet for containers
  201. ```
  202. calicoctl pool show
  203. ```
  204. * Show the workloads (ip addresses of containers and their located)
  205. ```
  206. calicoctl endpoint show --detail
  207. ```
  208. #### Flannel networking
  209. Congrats ! now you can walk through [kubernetes basics](http://kubernetes.io/v1.1/basicstutorials.html)