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.

320 lines
8.9 KiB

8 years ago
8 years ago
8 years ago
9 years ago
8 years ago
9 years ago
9 years ago
8 years ago
9 years ago
8 years ago
9 years ago
9 years ago
8 years ago
9 years ago
8 years ago
9 years ago
9 years ago
8 years ago
8 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
8 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
8 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. [![Build Status](https://travis-ci.org/kubespray/setup-kubernetes.svg)](https://travis-ci.org/kubespray/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 within 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. Linux distributions tested:
  10. * **Debian** Wheezy, Jessie
  11. * **Ubuntu** 14.10, 15.04, 15.10
  12. * **Fedora** 23
  13. * **CentOS** 7 (Currently with flannel only)
  14. ### Requirements
  15. * The target servers must have **access to the Internet** in order to pull docker imaqes.
  16. * The **firewalls are not managed**, you'll need to implement your own rules the way you used to.
  17. in order to avoid any issue during deployment you should disable your firewall
  18. * **Copy your ssh keys** to all the servers part of your inventory.
  19. * **Ansible v2.x and python-netaddr**
  20. * Base knowledge on Ansible. Please refer to [Ansible documentation](http://www.ansible.com/how-ansible-works)
  21. ### Components
  22. * [kubernetes](https://github.com/kubernetes/kubernetes/releases) v1.1.4
  23. * [etcd](https://github.com/coreos/etcd/releases) v2.2.4
  24. * [calicoctl](https://github.com/projectcalico/calico-docker/releases) v0.16.0
  25. * [flanneld](https://github.com/coreos/flannel/releases) v0.5.5
  26. * [weave](http://weave.works/) v1.4.4
  27. * [docker](https://www.docker.com/) v1.9.1
  28. Quickstart
  29. -------------------------
  30. The following steps will quickly setup a kubernetes cluster with default configuration.
  31. These defaults are good for tests purposes.
  32. Edit the inventory according to the number of servers
  33. ```
  34. [kube-master]
  35. node1
  36. node2
  37. [etcd]
  38. node1
  39. node2
  40. node3
  41. [kube-node]
  42. node2
  43. node3
  44. node4
  45. node5
  46. node6
  47. [k8s-cluster:children]
  48. kube-node
  49. kube-master
  50. ```
  51. Run the playbook
  52. ```
  53. ansible-playbook -i inventory/inventory.cfg cluster.yml -u root
  54. ```
  55. You can jump directly to "*Available apps, installation procedure*"
  56. Ansible
  57. -------------------------
  58. ### Variables
  59. The main variables to change are located in the directory ```inventory/group_vars/all.yml```.
  60. ### Inventory
  61. Below is an example of an inventory.
  62. ```
  63. ## Configure 'ip' variable to bind kubernetes services on a
  64. ## different ip than the default iface
  65. node1 ansible_ssh_host=95.54.0.12 # ip=10.3.0.1
  66. node2 ansible_ssh_host=95.54.0.13 # ip=10.3.0.2
  67. node3 ansible_ssh_host=95.54.0.14 # ip=10.3.0.3
  68. node4 ansible_ssh_host=95.54.0.15 # ip=10.3.0.4
  69. node5 ansible_ssh_host=95.54.0.16 # ip=10.3.0.5
  70. node6 ansible_ssh_host=95.54.0.17 # ip=10.3.0.6
  71. [kube-master]
  72. node1
  73. node2
  74. [etcd]
  75. node1
  76. node2
  77. node3
  78. [kube-node]
  79. node2
  80. node3
  81. node4
  82. node5
  83. node6
  84. [k8s-cluster:children]
  85. kube-node
  86. kube-master
  87. ```
  88. ### Playbook
  89. ```
  90. ---
  91. - hosts: k8s-cluster
  92. roles:
  93. - { role: adduser, tags: adduser }
  94. - { role: download, tags: download }
  95. - { role: kubernetes/preinstall, tags: preinstall }
  96. - { role: etcd, tags: etcd }
  97. - { role: docker, tags: docker }
  98. - { role: kubernetes/node, tags: node }
  99. - { role: network_plugin, tags: network }
  100. - { role: dnsmasq, tags: dnsmasq }
  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. * For safety reasons, you should have at least two master nodes and 3 etcd servers
  117. * 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.
  118. In order to do so, some variables have to be used '**loadbalancer_apiserver**' and '**apiserver_loadbalancer_domain_name**'
  119. ### Network Plugin
  120. You can choose between 3 network plugins. Only one must be chosen.
  121. * **flannel**: gre/vxlan (layer 2) networking. ([official docs](https://github.com/coreos/flannel))
  122. * **calico**: bgp (layer 3) networking. ([official docs](http://docs.projectcalico.org/en/0.13/))
  123. * **weave**: Weave is a lightweight container overlay network that doesn't require an external K/V database cluster. ([official docs](http://weave.works/docs/))
  124. The choice is defined with the variable **kube_network_plugin**
  125. ### Check cluster status
  126. #### Kubernetes components
  127. * Check the status of the processes
  128. ```
  129. systemctl status kubelet
  130. ```
  131. * Check the logs
  132. ```
  133. journalctl -ae -u kubelet
  134. ```
  135. * Check the NAT rules
  136. ```
  137. iptables -nLv -t nat
  138. ```
  139. For the master nodes you'll have to see the docker logs for the apiserver
  140. ```
  141. docker logs [apiserver docker id]
  142. ```
  143. ### Available apps, installation procedure
  144. There are two ways of installing new apps
  145. #### Ansible galaxy
  146. Additionnal apps can be installed with ```ansible-galaxy```.
  147. you'll need to edit the file '*requirements.yml*' in order to chose needed apps.
  148. The list of available apps are available [there](https://github.com/ansibl8s)
  149. For instance it is **strongly recommanded** to install a dns server which resolves kubernetes service names.
  150. In order to use this role you'll need the following entries in the file '*requirements.yml*'
  151. Please refer to the [k8s-kubedns readme](https://github.com/ansibl8s/k8s-kubedns) for additionnal info.
  152. ```
  153. - src: https://github.com/ansibl8s/k8s-common.git
  154. path: roles/apps
  155. # version: v1.0
  156. - src: https://github.com/ansibl8s/k8s-kubedns.git
  157. path: roles/apps
  158. # version: v1.0
  159. ```
  160. **Note**: the role common is required by all the apps and provides the tasks and libraries needed.
  161. And empty the apps directory
  162. ```
  163. rm -rf roles/apps/*
  164. ```
  165. Then download the roles with ansible-galaxy
  166. ```
  167. ansible-galaxy install -r requirements.yml
  168. ```
  169. Finally update the playbook ```apps.yml``` with the chosen roles, and run it
  170. ```
  171. ...
  172. - hosts: kube-master
  173. roles:
  174. - { role: apps/k8s-kubedns, tags: ['kubedns', 'apps'] }
  175. ...
  176. ```
  177. ```
  178. ansible-playbook -i inventory/inventory.cfg apps.yml -u root
  179. ```
  180. #### Git submodules
  181. Alternatively the roles can be installed as git submodules.
  182. That way is easier if you want to do some changes and commit them.
  183. ### Networking
  184. #### Calico
  185. Check if the calico-node container is running
  186. ```
  187. docker ps | grep calico
  188. ```
  189. The **calicoctl** command allows to check the status of the network workloads.
  190. * Check the status of Calico nodes
  191. ```
  192. calicoctl status
  193. ```
  194. * Show the configured network subnet for containers
  195. ```
  196. calicoctl pool show
  197. ```
  198. * Show the workloads (ip addresses of containers and their located)
  199. ```
  200. calicoctl endpoint show --detail
  201. ```
  202. ##### Optionnal : BGP Peering with border routers
  203. In some cases you may want to route the pods subnet and so NAT is not needed on the nodes.
  204. For instance if you have a cluster spread on different locations and you want your pods to talk each other no matter where they are located.
  205. The following variables need to be set:
  206. **peer_with_router** enable the peering with border router of the datacenter (default value: false).
  207. you'll need to edit the inventory and add a and a hostvar **local_as** by node.
  208. ```
  209. node1 ansible_ssh_host=95.54.0.12 local_as=xxxxxx
  210. ```
  211. #### Flannel
  212. * Flannel configuration file should have been created there
  213. ```
  214. cat /run/flannel/subnet.env
  215. FLANNEL_NETWORK=10.233.0.0/18
  216. FLANNEL_SUBNET=10.233.16.1/24
  217. FLANNEL_MTU=1450
  218. FLANNEL_IPMASQ=false
  219. ```
  220. * Check if the network interface has been created
  221. ```
  222. ip a show dev flannel.1
  223. 4: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default
  224. link/ether e2:f3:a7:0f:bf:cb brd ff:ff:ff:ff:ff:ff
  225. inet 10.233.16.0/18 scope global flannel.1
  226. valid_lft forever preferred_lft forever
  227. inet6 fe80::e0f3:a7ff:fe0f:bfcb/64 scope link
  228. valid_lft forever preferred_lft forever
  229. ```
  230. * Docker must be configured with a bridge ip in the flannel subnet.
  231. ```
  232. ps aux | grep docker
  233. root 20196 1.7 2.7 1260616 56840 ? Ssl 10:18 0:07 /usr/bin/docker daemon --bip=10.233.16.1/24 --mtu=1450
  234. ```
  235. * Try to run a container and check its ip address
  236. ```
  237. kubectl run test --image=busybox --command -- tail -f /dev/null
  238. replicationcontroller "test" created
  239. kubectl describe po test-34ozs | grep ^IP
  240. IP: 10.233.16.2
  241. ```
  242. ```
  243. kubectl exec test-34ozs -- ip a show dev eth0
  244. 8: eth0@if9: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1450 qdisc noqueue
  245. link/ether 02:42:0a:e9:2b:03 brd ff:ff:ff:ff:ff:ff
  246. inet 10.233.16.2/24 scope global eth0
  247. valid_lft forever preferred_lft forever
  248. inet6 fe80::42:aff:fee9:2b03/64 scope link tentative flags 08
  249. valid_lft forever preferred_lft forever
  250. ```
  251. Congrats ! now you can walk through [kubernetes basics](http://kubernetes.io/v1.1/basicstutorials.html)