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.

215 lines
6.7 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
  1. kubernetes-ansible
  2. ========
  3. Install and configure a kubernetes cluster including network overlay 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.0.6
  12. * [etcd](https://github.com/coreos/etcd/releases) v2.2.0
  13. * [calicoctl](https://github.com/projectcalico/calico-docker/releases) v0.5.1
  14. * [flanneld](https://github.com/coreos/flannel/releases) v0.5.3
  15. * [docker](https://www.docker.com/) v1.8.2
  16. Ansible
  17. -------------------------
  18. ### Download binaries
  19. A role allows to download required binaries which 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. ### Playbook
  26. ```
  27. ---
  28. - hosts: downloader
  29. sudo: no
  30. roles:
  31. - { role: download, tags: download }
  32. - hosts: k8s-cluster
  33. roles:
  34. - { role: etcd, tags: etcd }
  35. - { role: docker, tags: docker }
  36. - { role: overlay_network, tags: ['calico', 'flannel', 'network'] }
  37. - { role: dnsmasq, tags: dnsmasq }
  38. - hosts: kube-master
  39. roles:
  40. - { role: kubernetes/master, tags: master }
  41. - { role: apps/k8s-fabric8, tags: ['fabric8', 'apps'] }
  42. - hosts: kube-node
  43. roles:
  44. - { role: kubernetes/node, tags: node }
  45. - hosts: kube-master
  46. roles:
  47. - { role: apps/k8s-kubedns, tags: ['kubedns', 'apps'] }
  48. - { role: apps/k8s-fabric8, tags: ['fabric8', 'apps'] }
  49. ```
  50. ### Run
  51. It is possible to define variables for different environments.
  52. For instance, in order to deploy the cluster on 'dev' environment run the following command.
  53. ```
  54. ansible-playbook -i environments/dev/inventory cluster.yml -u root
  55. ```
  56. Kubernetes
  57. -------------------------
  58. ### Network Overlay
  59. You can choose between 2 network overlays. Only one must be chosen.
  60. * **flannel**: gre/vxlan (layer 2) networking. ([official docs]('https://github.com/coreos/flannel'))
  61. * **calico**: bgp (layer 3) networking. ([official docs]('http://docs.projectcalico.org/en/0.13/'))
  62. The choice is defined with the variable '**overlay_network_plugin**'
  63. ### Expose a service
  64. There are several loadbalancing solutions.
  65. The ones i found suitable for kubernetes are [Vulcand]('http://vulcand.io/') and [Haproxy]('http://www.haproxy.org/')
  66. My cluster is working with haproxy and kubernetes services are configured with the loadbalancing type '**nodePort**'.
  67. eg: each node opens the same tcp port and forwards the traffic to the target pod wherever it is located.
  68. Then Haproxy can be configured to request kubernetes's api in order to loadbalance on the proper tcp port on the nodes.
  69. Please refer to the proper kubernetes documentation on [Services]('https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/user-guide/services.md')
  70. ### Check cluster status
  71. #### Kubernetes components
  72. Master processes : kube-apiserver, kube-scheduler, kube-controller, kube-proxy
  73. Nodes processes : kubelet, kube-proxy, [calico-node|flanneld]
  74. * Check the status of the processes
  75. ```
  76. systemctl status [process_name]
  77. ```
  78. * Check the logs
  79. ```
  80. journalctl -ae -u [process_name]
  81. ```
  82. * Check the NAT rules
  83. ```
  84. iptables -nLv -t nat
  85. ```
  86. ### Available apps, installation procedure
  87. There are two ways of installing new apps
  88. #### Ansible galaxy
  89. Additionnal apps can be installed with ```ansible-galaxy```.
  90. you'll need to edit the file '*requirements.yml*' in order to chose needed apps.
  91. The list of available apps are available [there](https://github.com/ansibl8s)
  92. For instance if you will probably want to install a [dns server](https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns) as it is **strongly recommanded**.
  93. In order to use this role you'll need the following entries in the file '*requirements.yml*'
  94. ```
  95. - src: https://github.com/ansibl8s/k8s-common.git
  96. path: roles/apps
  97. # version: v1.0
  98. - src: https://github.com/ansibl8s/k8s-kubedns.git
  99. path: roles/apps
  100. # version: v1.0
  101. ```
  102. **Note**: the role common is required by all the apps and provides the tasks and libraries needed.
  103. And empty the apps directory
  104. ```
  105. rm -rf roles/apps/*
  106. ```
  107. Then download the roles with ansible-galaxy
  108. ```
  109. ansible-galaxy install -r requirements.yml
  110. ```
  111. #### Git submodules
  112. Alternatively the roles can be installed as git submodules.
  113. That way is easier if you want to do some changes and commit them.
  114. You can list available submodules with the following command:
  115. ```
  116. grep path .gitmodules | sed 's/.*= //'
  117. ```
  118. For instance if you will probably want to install a [dns server](https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns) as it is **strongly recommanded**.
  119. In order to use this role you'll need to follow these steps
  120. ```
  121. git submodule init roles/apps/k8s-common roles/apps/k8s-kubedns
  122. git submodule update
  123. ```
  124. Finally update your playbook with the chosen role, and run it
  125. ```
  126. ...
  127. - hosts: kube-master
  128. roles:
  129. - { role: apps/k8s-kubedns, tags: ['kubedns', 'apps'] }
  130. ...
  131. ```
  132. Please refer to the [k8s-kubdns readme](https://github.com/ansibl8s/k8s-kubedns) for additionnal info.
  133. #### Calico networking
  134. Check if the calico-node container is running
  135. ```
  136. docker ps | grep calico
  137. ```
  138. The **calicoctl** command allows to check the status of the network workloads.
  139. * Check the status of Calico nodes
  140. ```
  141. calicoctl status
  142. ```
  143. * Show the configured network subnet for containers
  144. ```
  145. calicoctl pool show
  146. ```
  147. * Show the workloads (ip addresses of containers and their located)
  148. ```
  149. calicoctl endpoint show --detail
  150. ```
  151. #### Flannel networking
  152. Congrats ! now you can walk through [kubernetes basics](http://kubernetes.io/v1.0/basicstutorials.html)
  153. Known issues
  154. -------------
  155. ### Node reboot and Calico
  156. There is a major issue with calico-kubernetes version 0.5.1 and kubernetes prior to 1.1 :
  157. After host reboot, the pods networking are not configured again, they are started without any network configuration.
  158. This issue will be fixed when kubernetes 1.1 will be released as described in this [issue](https://github.com/projectcalico/calico-kubernetes/issues/34)
  159. ### Monitoring addon
  160. Until now i didn't managed to get the monitoring addon working.
  161. ### Apiserver listen on secure port only
  162. Currently the api-server listens on both secure and insecure ports.
  163. The insecure port is mainly used for calico.
  164. Will be fixed soon.