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.

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