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.

194 lines
5.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
  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: addons, tags: addons }
  42. - hosts: kube-node
  43. roles:
  44. - { role: kubernetes/node, tags: node }
  45. ```
  46. ### Run
  47. It is possible to define variables for different environments.
  48. For instance, in order to deploy the cluster on 'dev' environment run the following command.
  49. ```
  50. ansible-playbook -i environments/dev/inventory cluster.yml -u root
  51. ```
  52. Kubernetes
  53. -------------------------
  54. ### Network Overlay
  55. You can choose between 2 network overlays. Only one must be chosen.
  56. * **flannel**: gre/vxlan (layer 2) networking. ([official docs]('https://github.com/coreos/flannel'))
  57. * **calico**: bgp (layer 3) networking. ([official docs]('http://docs.projectcalico.org/en/0.13/'))
  58. The choice is defined with the variable '**overlay_network_plugin**'
  59. ### Expose a service
  60. There are several loadbalancing solutions.
  61. The ones i found suitable for kubernetes are [Vulcand]('http://vulcand.io/') and [Haproxy]('http://www.haproxy.org/')
  62. My cluster is working with haproxy and kubernetes services are configured with the loadbalancing type '**nodePort**'.
  63. eg: each node opens the same tcp port and forwards the traffic to the target pod wherever it is located.
  64. Then Haproxy can be configured to request kubernetes's api in order to loadbalance on the proper tcp port on the nodes.
  65. Please refer to the proper kubernetes documentation on [Services]('https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/user-guide/services.md')
  66. ### Check cluster status
  67. #### Kubernetes components
  68. Master processes : kube-apiserver, kube-scheduler, kube-controller, kube-proxy
  69. Nodes processes : kubelet, kube-proxy, [calico-node|flanneld]
  70. * Check the status of the processes
  71. ```
  72. systemctl status [process_name]
  73. ```
  74. * Check the logs
  75. ```
  76. journalctl -ae -u [process_name]
  77. ```
  78. * Check the NAT rules
  79. ```
  80. iptables -nLv -t nat
  81. ```
  82. #### Available addons
  83. By default 3 addons are enabled
  84. * A dns server in order to resolve kubernetes services names
  85. * [Kube-ui](https://github.com/kubernetes/kube-ui) which is a simple dashboard which shows kubernete's components, url : ``` http://[master_ip]:8080/ui```
  86. * [Fabric8](http://fabric8.io/), console management for kubernetes : ```http://[master_ip]:8080/api/v1/proxy/namespaces/default/services/fabric8```
  87. Other addons : logging, monitoring
  88. #### Calico networking
  89. Check if the calico-node container is running
  90. ```
  91. docker ps | grep calico
  92. ```
  93. The **calicoctl** command allows to check the status of the network workloads.
  94. * Check the status of Calico nodes
  95. ```
  96. calicoctl status
  97. ```
  98. * Show the configured network subnet for containers
  99. ```
  100. calicoctl pool show
  101. ```
  102. * Show the workloads (ip addresses of containers and their located)
  103. ```
  104. calicoctl endpoint show --detail
  105. ```
  106. #### Flannel networking
  107. #### Test the dns server
  108. * Create a file 'busybox.yaml' with the following content
  109. ```
  110. apiVersion: v1
  111. kind: Pod
  112. metadata:
  113. name: busybox
  114. namespace: default
  115. spec:
  116. containers:
  117. - image: busybox
  118. command:
  119. - sleep
  120. - "3600"
  121. imagePullPolicy: IfNotPresent
  122. name: busybox
  123. restartPolicy: Always
  124. ```
  125. * Create the pod
  126. ```
  127. kubectl create -f busybox.yaml
  128. ```
  129. * When the pod is ready, execute the following command
  130. ```
  131. kubectl exec busybox -- nslookup kubernetes.default
  132. ```
  133. You should get an answer from the configured dns server
  134. Congrats ! now you can walk through [kubernetes basics](http://kubernetes.io/v1.0/basicstutorials.html)
  135. Known issues
  136. -------------
  137. ### Node reboot and Calico
  138. There is a major issue with calico-kubernetes version 0.5.1 and kubernetes prior to 1.1 :
  139. After host reboot, the pods networking are not configured again, they are started without any network configuration.
  140. 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)
  141. ### Monitoring addon
  142. Until now i didn't managed to get the monitoring addon working.
  143. ### Listen on secure port only
  144. Currently the api-server listens on both secure and insecure ports.
  145. The insecure port is mainly used for calico.
  146. Will be fixed soon.
  147. Author Information
  148. ------------------
  149. Smana - Smaine Kahlouch (smainklh@gmail.com)