├── .gitignore ├── .travis.yml ├── .travis ├── create_droplets.py └── delete_droplets.py ├── LICENSE ├── README.md ├── bootstrap.yaml ├── group_vars └── all.yaml ├── image.png ├── init_kube.yaml ├── init_os.yaml ├── inventory ├── requirements.txt └── roles ├── create_network ├── tasks │ └── main.yaml └── templates │ ├── calico.yaml │ ├── kube-proxy.yaml │ └── rbac.yaml ├── etcd ├── meta │ └── main.yaml ├── tasks │ └── main.yaml └── templates │ ├── etcd.conf.j2 │ └── openssl.cnf.j2 ├── helm ├── files │ └── rbac-config.yaml └── tasks │ └── main.yaml ├── init_master ├── tasks │ └── main.yml └── templates │ └── kubeadm.conf.j2 ├── init_slave ├── meta │ └── main.yaml └── tasks │ └── main.yaml ├── reboot └── tasks │ └── main.yaml ├── selinux └── tasks │ └── main.yaml └── software ├── tasks └── main.yaml └── templates └── k8s.conf /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.retry 3 | 4 | kubetoken 5 | .travis/listip 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - 3.5 4 | env: 5 | global: 6 | - 'ANSIBLE_HOST_KEY_CHECKING=False' 7 | install: 8 | - pip install -r requirements.txt 9 | before_script: 10 | - python .travis/create_droplets.py 11 | - eval "$(ssh-agent -s)" 12 | - echo ${SSH_KEY} | base64 -d > /tmp/id_rsa 13 | - chmod 600 /tmp/id_rsa 14 | - ssh-add /tmp/id_rsa 15 | script: 16 | - cat inventory 17 | - ansible-playbook bootstrap.yaml -i inventory 18 | after_script: 19 | - python .travis/delete_droplets.py 20 | -------------------------------------------------------------------------------- /.travis/create_droplets.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | import time 4 | import json 5 | import configparser 6 | 7 | def create_droplets(token, build, ssh_keys): 8 | url = "https://api.digitalocean.com/v2/droplets" 9 | headers = {"Authorization": "Bearer {}".format(token)} 10 | data = {"names": 11 | [ 12 | "m1.train", 13 | "s1.train" 14 | ], 15 | "region": "nyc3", 16 | "size": "s-1vcpu-1gb", 17 | "image": "centos-7-x64", 18 | "ssh_keys": [ssh_keys], 19 | "backups": False, 20 | "ipv6": False, 21 | "user_data": None, 22 | "private_networking": True, 23 | "tags": ["travis-ci", "letskube", build]} 24 | r = requests.post(url, headers=headers, json=data) 25 | if 200 <= r.status_code < 300: 26 | print("droplets created") 27 | else: 28 | print("droplets don't created: %s" % r.status_code) 29 | exit(1) 30 | 31 | def get_droplets(token, tag): 32 | url = "https://api.digitalocean.com/v2/droplets" 33 | headers = {"Authorization": "Bearer {}".format(token)} 34 | data = {"tag_name": tag} 35 | r = requests.get(url, headers=headers, params=data) 36 | return json.loads(r.text) 37 | 38 | def wait_status(token, tag): 39 | start = time.time() 40 | counter = 0 41 | print("Wait active status") 42 | while time.time() < start + 120: 43 | counter += 1 44 | print("# {}".format(counter)) 45 | droplets = get_droplets(token, tag) 46 | all_status = True 47 | for droplet in droplets["droplets"]: 48 | name_droplet = droplet["name"] 49 | status_droplet = droplet["status"] 50 | print(name_droplet, status_droplet) 51 | if status_droplet != "active": 52 | all_status = False 53 | if all_status: 54 | time.sleep(60) #wait loading 55 | break 56 | time.sleep(2) 57 | 58 | def get_ip_for_droplets(token, tag): 59 | network = {} 60 | droplets = get_droplets(token, tag) 61 | for droplet in droplets["droplets"]: 62 | name_droplet = droplet["name"] 63 | network_droplet = droplet["networks"]["v4"] 64 | network[name_droplet] = {} 65 | for ip in droplet["networks"]["v4"]: 66 | type = ip["type"] 67 | ip_addr = ip["ip_address"] 68 | network[name_droplet][type] = ip_addr 69 | return network 70 | 71 | def get_inventory(path=None): 72 | inventory = configparser.ConfigParser(allow_no_value=True, delimiters=('\t', ' ')) 73 | if path: 74 | inventory.read(path) 75 | return inventory 76 | 77 | def change_inventory(inventory, droplets): 78 | for droplet in droplets: 79 | node = droplet 80 | public_ip = network[droplet]['public'] 81 | private_ip = network[droplet]['private'] 82 | param = "ansible_user=root ansible_host={} ansible_port=22 ip_internal={}".format(public_ip, private_ip) 83 | inventory.set("all", node, param) 84 | 85 | 86 | def write_inventory(inventory, path=None): 87 | with open(path, 'w') as f: 88 | inventory.write(f) 89 | 90 | def write_ip_for_test(droplets, path=None): 91 | with open(path, 'w') as f: 92 | for droplet in droplets: 93 | public_ip = network[droplet]['public'] 94 | f.write(public_ip + '\n') 95 | 96 | def get_env(): 97 | return os.environ['DO_TOKEN'], os.environ['TRAVIS_BUILD_ID'], os.environ['DO_SSH_KEYS'] 98 | 99 | if __name__ == "__main__": 100 | token, tag, ssh_keys = get_env() 101 | path_to_repos = os.environ['TRAVIS_BUILD_DIR'] 102 | path_to_inventory = os.path.join(path_to_repos, "inventory") 103 | path_to_listip = os.path.join(path_to_repos, ".travis/listip") 104 | 105 | create_droplets(token, tag, ssh_keys) 106 | wait_status(token, tag) 107 | 108 | network = get_ip_for_droplets(token, tag) 109 | inventory = get_inventory(path=path_to_inventory) 110 | change_inventory(inventory, network) 111 | write_inventory(inventory, path=path_to_inventory) 112 | write_ip_for_test(network, path_to_listip) -------------------------------------------------------------------------------- /.travis/delete_droplets.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | def delete_droplets(token, tag): 5 | url = "https://api.digitalocean.com/v2/droplets" 6 | headers = {"Authorization": "Bearer {}".format(token)} 7 | data = {"tag_name": tag} 8 | r = requests.delete(url, headers=headers, params=data) 9 | if 200 <= r.status_code < 300: 10 | print("droplets deleted") 11 | 12 | 13 | if __name__ == "__main__": 14 | token = os.environ['DO_TOKEN'] 15 | tag = os.environ['TRAVIS_BUILD_ID'] 16 | delete_droplets(token=token, tag=tag) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 Containerum 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Let's Kube 2 | 3 | ![Let's Kube](image.png) 4 | 5 | **Work in progress** 6 | 7 | Ansible playbooks for deploying a Kubernetes cluster on virtual machines with CentOS 7. 8 | 9 | 10 | **Requirements:** 11 | 12 | - Ansible *2.1 or higher* 13 | - CentOS 7 14 | 15 | 16 | ## Installation 17 | 18 | Add your nodes in inventory. 19 | 20 | In group_vars: 21 | internal_net - internal subnet for kube-api, etcd, calico 22 | 23 | Start: 24 | ``` 25 | ansible-playbook bootstrap.yaml -i inventory 26 | ``` 27 | 28 | 29 | ## Roadmap 30 | 31 | - [x] install docker 17.12.1 32 | - [x] install kubelet, kubectl, kubeadm 1.9.* 33 | - [x] install etcd on host 34 | - [x] init 1 master and multiple slaves 35 | - [x] make admin.conf 36 | - [x] install calico 37 | - [ ] install etcd on multiple hosts 38 | - [ ] backup and restore etcd 39 | - [ ] init multi-master 40 | - [ ] install flannel, canal 41 | - [ ] update Kubernetes cluster 42 | -------------------------------------------------------------------------------- /bootstrap.yaml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | become: true 3 | roles: 4 | - selinux 5 | - software 6 | - etcd 7 | 8 | - hosts: masters 9 | roles: 10 | - init_master 11 | 12 | - hosts: slaves 13 | roles: 14 | - init_slave 15 | 16 | - hosts: kubectl 17 | roles: 18 | - create_network 19 | -------------------------------------------------------------------------------- /group_vars/all.yaml: -------------------------------------------------------------------------------- 1 | internal_net: 0.0.0.0/0 2 | calico_interface: eth1 3 | -------------------------------------------------------------------------------- /image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/containerum/letskube/76bfa67a00436bb4fc76e257e6ce8e6bbe8fabc0/image.png -------------------------------------------------------------------------------- /init_kube.yaml: -------------------------------------------------------------------------------- 1 | - hosts: masters 2 | become: true 3 | roles: 4 | - init_master 5 | 6 | - hosts: slaves 7 | become: true 8 | #strategy: linear 9 | roles: 10 | - init_slave 11 | 12 | - hosts: kubectl 13 | roles: 14 | - helm 15 | -------------------------------------------------------------------------------- /init_os.yaml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | roles: 3 | - selinux 4 | - software 5 | - reboot 6 | -------------------------------------------------------------------------------- /inventory: -------------------------------------------------------------------------------- 1 | [all] 2 | m1.train ansible_user=centos ansible_host=172.16.0.1 ansible_port=22 ip_internal=10.0.0.1 3 | s1.train ansible_user=centos ansible_host=172.16.0.2 ansible_port=22 ip_internal=10.0.0.2 4 | 5 | [masters] 6 | m1.train 7 | 8 | [slaves] 9 | s1.train 10 | 11 | [kubectl] 12 | m1.train 13 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | ansible==2.5.2 2 | requests==2.18.4 3 | netaddr==0.7.19 4 | -------------------------------------------------------------------------------- /roles/create_network/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | # fix me 2 | #- name: get ip 3 | # vars: 4 | # ip_list: "{{ ansible_all_ipv4_addresses | ipaddr(internal_net) }}" 5 | # set_fact: 6 | # ip_internal: "{{ ip_list | join('\n') }}" 7 | 8 | - name: get ca.pem 9 | raw: "cat /etc/ssl/etcd/ca.pem | base64 -w 0" 10 | register: etcd_ca 11 | 12 | - name: get etcd-client.pem 13 | raw: "cat /etc/ssl/etcd/etcd-client.pem | base64 -w 0" 14 | register: etcd_pem 15 | 16 | - name: get etcd-client-key.pem 17 | raw: "cat /etc/ssl/etcd/etcd-client-key.pem | base64 -w 0" 18 | register: etcd_key 19 | 20 | - name: copy calico.yaml 21 | template: 22 | src: templates/calico.yaml 23 | dest: /tmp/calico.yaml 24 | 25 | - name: copy rbac.yaml 26 | template: 27 | src: templates/rbac.yaml 28 | dest: /tmp/rbac.yaml 29 | 30 | - name: copy kube-proxy.yaml 31 | template: 32 | src: templates/kube-proxy.yaml 33 | dest: /tmp/kube-proxy.yaml 34 | 35 | - name: Delete old kube-proxy 36 | raw: kubectl delete -f /tmp/kube-proxy.yaml 37 | ignore_errors: true 38 | 39 | - name: Create kube-proxy 40 | raw: kubectl create -f /tmp/kube-proxy.yaml 41 | 42 | - name: Delete old RBAC 43 | raw: kubectl delete -f /tmp/rbac.yaml 44 | ignore_errors: true 45 | 46 | - name: Delete old Calico 47 | raw: kubectl delete -f /tmp/calico.yaml 48 | ignore_errors: true 49 | 50 | - name: Create RBAC 51 | raw: kubectl create -f /tmp/rbac.yaml 52 | 53 | - name: Create Calico 54 | raw: kubectl create -f /tmp/calico.yaml 55 | -------------------------------------------------------------------------------- /roles/create_network/templates/calico.yaml: -------------------------------------------------------------------------------- 1 | # Calico Version v3.1.0 2 | # https://docs.projectcalico.org/v3.1/releases#v3.1.0 3 | # This manifest includes the following component versions: 4 | # calico/node:v3.1.0 5 | # calico/cni:v3.1.0 6 | # calico/kube-controllers:v3.1.0 7 | 8 | # This ConfigMap is used to configure a self-hosted Calico installation. 9 | kind: ConfigMap 10 | apiVersion: v1 11 | metadata: 12 | name: calico-config 13 | namespace: kube-system 14 | data: 15 | # Configure this with the location of your etcd cluster. 16 | etcd_endpoints: "https://{{ ip_internal }}:2379" 17 | 18 | # Configure the Calico backend to use. 19 | calico_backend: "bird" 20 | 21 | # The CNI network configuration to install on each node. 22 | cni_network_config: |- 23 | { 24 | "name": "k8s-pod-network", 25 | "cniVersion": "0.3.0", 26 | "plugins": [ 27 | { 28 | "type": "calico", 29 | "etcd_endpoints": "__ETCD_ENDPOINTS__", 30 | "etcd_key_file": "__ETCD_KEY_FILE__", 31 | "etcd_cert_file": "__ETCD_CERT_FILE__", 32 | "etcd_ca_cert_file": "__ETCD_CA_CERT_FILE__", 33 | "log_level": "info", 34 | "mtu": 1500, 35 | "ipam": { 36 | "type": "calico-ipam" 37 | }, 38 | "policy": { 39 | "type": "k8s" 40 | }, 41 | "kubernetes": { 42 | "kubeconfig": "__KUBECONFIG_FILEPATH__" 43 | } 44 | }, 45 | { 46 | "type": "portmap", 47 | "snat": true, 48 | "capabilities": {"portMappings": true} 49 | } 50 | ] 51 | } 52 | 53 | # If you're using TLS enabled etcd uncomment the following. 54 | # You must also populate the Secret below with these files. 55 | etcd_ca: "/calico-secrets/etcd-ca" 56 | etcd_cert: "/calico-secrets/etcd-cert" 57 | etcd_key: "/calico-secrets/etcd-key" 58 | 59 | --- 60 | 61 | # The following contains k8s Secrets for use with a TLS enabled etcd cluster. 62 | # For information on populating Secrets, see http://kubernetes.io/docs/user-guide/secrets/ 63 | apiVersion: v1 64 | kind: Secret 65 | type: Opaque 66 | metadata: 67 | name: calico-etcd-secrets 68 | namespace: kube-system 69 | data: 70 | # Populate the following files with etcd TLS configuration if desired, but leave blank if 71 | # not using TLS for etcd. 72 | # This self-hosted install expects three files with the following names. The values 73 | # should be base64 encoded strings of the entire contents of each file. 74 | etcd-key: "{{ etcd_key.stdout_lines[0] }}" 75 | etcd-cert: "{{ etcd_pem.stdout_lines[0] }}" 76 | etcd-ca: "{{ etcd_ca.stdout_lines[0] }}" 77 | 78 | --- 79 | 80 | # This manifest installs the calico/node container, as well 81 | # as the Calico CNI plugins and network config on 82 | # each master and worker node in a Kubernetes cluster. 83 | kind: DaemonSet 84 | apiVersion: extensions/v1beta1 85 | metadata: 86 | name: calico-node 87 | namespace: kube-system 88 | labels: 89 | k8s-app: calico-node 90 | spec: 91 | selector: 92 | matchLabels: 93 | k8s-app: calico-node 94 | updateStrategy: 95 | type: RollingUpdate 96 | rollingUpdate: 97 | maxUnavailable: 1 98 | template: 99 | metadata: 100 | labels: 101 | k8s-app: calico-node 102 | annotations: 103 | scheduler.alpha.kubernetes.io/critical-pod: '' 104 | spec: 105 | hostNetwork: true 106 | tolerations: 107 | # Make sure calico/node gets scheduled on all nodes. 108 | - effect: NoSchedule 109 | operator: Exists 110 | # Mark the pod as a critical add-on for rescheduling. 111 | - key: CriticalAddonsOnly 112 | operator: Exists 113 | - effect: NoExecute 114 | operator: Exists 115 | serviceAccountName: calico-node 116 | # Minimize downtime during a rolling upgrade or deletion; tell Kubernetes to do a "force 117 | # deletion": https://kubernetes.io/docs/concepts/workloads/pods/pod/#termination-of-pods. 118 | terminationGracePeriodSeconds: 0 119 | containers: 120 | # Runs calico/node container on each Kubernetes node. This 121 | # container programs network policy and routes on each 122 | # host. 123 | - name: calico-node 124 | image: quay.io/calico/node:v3.1.0 125 | env: 126 | # The location of the Calico etcd cluster. 127 | - name: ETCD_ENDPOINTS 128 | valueFrom: 129 | configMapKeyRef: 130 | name: calico-config 131 | key: etcd_endpoints 132 | # Choose the backend to use. 133 | - name: CALICO_NETWORKING_BACKEND 134 | valueFrom: 135 | configMapKeyRef: 136 | name: calico-config 137 | key: calico_backend 138 | # Cluster type to identify the deployment type 139 | - name: CLUSTER_TYPE 140 | value: "k8s,bgp" 141 | # Disable file logging so `kubectl logs` works. 142 | - name: CALICO_DISABLE_FILE_LOGGING 143 | value: "true" 144 | # Set noderef for node controller. 145 | - name: CALICO_K8S_NODE_REF 146 | valueFrom: 147 | fieldRef: 148 | fieldPath: spec.nodeName 149 | # Set Felix endpoint to host default action to ACCEPT. 150 | - name: FELIX_DEFAULTENDPOINTTOHOSTACTION 151 | value: "ACCEPT" 152 | # The default IPv4 pool to create on startup if none exists. Pod IPs will be 153 | # chosen from this range. Changing this value after installation will have 154 | # no effect. This should fall within `--cluster-cidr`. 155 | - name: IP_AUTODETECTION_METHOD 156 | value: "interface={{ calico_interface }}" 157 | - name: CALICO_IPV4POOL_CIDR 158 | value: "10.244.0.0/16" 159 | - name: CALICO_IPV4POOL_IPIP 160 | value: "Always" 161 | # Disable IPv6 on Kubernetes. 162 | - name: FELIX_IPV6SUPPORT 163 | value: "false" 164 | # Set Felix logging to "info" 165 | - name: FELIX_LOGSEVERITYSCREEN 166 | value: "info" 167 | # Set MTU for tunnel device used if ipip is enabled 168 | - name: FELIX_IPINIPMTU 169 | value: "1440" 170 | # Location of the CA certificate for etcd. 171 | - name: ETCD_CA_CERT_FILE 172 | valueFrom: 173 | configMapKeyRef: 174 | name: calico-config 175 | key: etcd_ca 176 | # Location of the client key for etcd. 177 | - name: ETCD_KEY_FILE 178 | valueFrom: 179 | configMapKeyRef: 180 | name: calico-config 181 | key: etcd_key 182 | # Location of the client certificate for etcd. 183 | - name: ETCD_CERT_FILE 184 | valueFrom: 185 | configMapKeyRef: 186 | name: calico-config 187 | key: etcd_cert 188 | # Auto-detect the BGP IP address. 189 | - name: IP 190 | value: "autodetect" 191 | - name: FELIX_HEALTHENABLED 192 | value: "true" 193 | securityContext: 194 | privileged: true 195 | resources: 196 | requests: 197 | cpu: 250m 198 | livenessProbe: 199 | httpGet: 200 | path: /liveness 201 | port: 9099 202 | periodSeconds: 10 203 | initialDelaySeconds: 10 204 | failureThreshold: 6 205 | readinessProbe: 206 | httpGet: 207 | path: /readiness 208 | port: 9099 209 | periodSeconds: 10 210 | volumeMounts: 211 | - mountPath: /lib/modules 212 | name: lib-modules 213 | readOnly: true 214 | - mountPath: /var/run/calico 215 | name: var-run-calico 216 | readOnly: false 217 | - mountPath: /var/lib/calico 218 | name: var-lib-calico 219 | readOnly: false 220 | - mountPath: /calico-secrets 221 | name: etcd-certs 222 | # This container installs the Calico CNI binaries 223 | # and CNI network config file on each node. 224 | - name: install-cni 225 | image: quay.io/calico/cni:v3.1.0 226 | command: ["/install-cni.sh"] 227 | env: 228 | # Name of the CNI config file to create. 229 | - name: CNI_CONF_NAME 230 | value: "10-calico.conflist" 231 | # The location of the Calico etcd cluster. 232 | - name: ETCD_ENDPOINTS 233 | valueFrom: 234 | configMapKeyRef: 235 | name: calico-config 236 | key: etcd_endpoints 237 | # The CNI network config to install on each node. 238 | - name: CNI_NETWORK_CONFIG 239 | valueFrom: 240 | configMapKeyRef: 241 | name: calico-config 242 | key: cni_network_config 243 | volumeMounts: 244 | - mountPath: /host/opt/cni/bin 245 | name: cni-bin-dir 246 | - mountPath: /host/etc/cni/net.d 247 | name: cni-net-dir 248 | - mountPath: /calico-secrets 249 | name: etcd-certs 250 | volumes: 251 | # Used by calico/node. 252 | - name: lib-modules 253 | hostPath: 254 | path: /lib/modules 255 | - name: var-run-calico 256 | hostPath: 257 | path: /var/run/calico 258 | - name: var-lib-calico 259 | hostPath: 260 | path: /var/lib/calico 261 | # Used to install CNI. 262 | - name: cni-bin-dir 263 | hostPath: 264 | path: /opt/cni/bin 265 | - name: cni-net-dir 266 | hostPath: 267 | path: /etc/cni/net.d 268 | # Mount in the etcd TLS secrets with mode 400. 269 | # See https://kubernetes.io/docs/concepts/configuration/secret/ 270 | - name: etcd-certs 271 | secret: 272 | secretName: calico-etcd-secrets 273 | defaultMode: 0400 274 | 275 | --- 276 | 277 | # This manifest deploys the Calico Kubernetes controllers. 278 | # See https://github.com/projectcalico/kube-controllers 279 | apiVersion: extensions/v1beta1 280 | kind: Deployment 281 | metadata: 282 | name: calico-kube-controllers 283 | namespace: kube-system 284 | labels: 285 | k8s-app: calico-kube-controllers 286 | annotations: 287 | scheduler.alpha.kubernetes.io/critical-pod: '' 288 | spec: 289 | # The controllers can only have a single active instance. 290 | replicas: 1 291 | strategy: 292 | type: Recreate 293 | template: 294 | metadata: 295 | name: calico-kube-controllers 296 | namespace: kube-system 297 | labels: 298 | k8s-app: calico-kube-controllers 299 | spec: 300 | # The controllers must run in the host network namespace so that 301 | # it isn't governed by policy that would prevent it from working. 302 | hostNetwork: true 303 | tolerations: 304 | # Mark the pod as a critical add-on for rescheduling. 305 | - key: CriticalAddonsOnly 306 | operator: Exists 307 | - key: node-role.kubernetes.io/master 308 | effect: NoSchedule 309 | serviceAccountName: calico-kube-controllers 310 | containers: 311 | - name: calico-kube-controllers 312 | image: quay.io/calico/kube-controllers:v3.1.0 313 | env: 314 | # The location of the Calico etcd cluster. 315 | - name: ETCD_ENDPOINTS 316 | valueFrom: 317 | configMapKeyRef: 318 | name: calico-config 319 | key: etcd_endpoints 320 | # Location of the CA certificate for etcd. 321 | - name: ETCD_CA_CERT_FILE 322 | valueFrom: 323 | configMapKeyRef: 324 | name: calico-config 325 | key: etcd_ca 326 | # Location of the client key for etcd. 327 | - name: ETCD_KEY_FILE 328 | valueFrom: 329 | configMapKeyRef: 330 | name: calico-config 331 | key: etcd_key 332 | # Location of the client certificate for etcd. 333 | - name: ETCD_CERT_FILE 334 | valueFrom: 335 | configMapKeyRef: 336 | name: calico-config 337 | key: etcd_cert 338 | # Choose which controllers to run. 339 | - name: ENABLED_CONTROLLERS 340 | value: policy,profile,workloadendpoint,node 341 | volumeMounts: 342 | # Mount in the etcd TLS secrets. 343 | - mountPath: /calico-secrets 344 | name: etcd-certs 345 | volumes: 346 | # Mount in the etcd TLS secrets with mode 400. 347 | # See https://kubernetes.io/docs/concepts/configuration/secret/ 348 | - name: etcd-certs 349 | secret: 350 | secretName: calico-etcd-secrets 351 | defaultMode: 0400 352 | 353 | --- 354 | 355 | apiVersion: v1 356 | kind: ServiceAccount 357 | metadata: 358 | name: calico-kube-controllers 359 | namespace: kube-system 360 | 361 | --- 362 | 363 | apiVersion: v1 364 | kind: ServiceAccount 365 | metadata: 366 | name: calico-node 367 | namespace: kube-system 368 | 369 | -------------------------------------------------------------------------------- /roles/create_network/templates/kube-proxy.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: DaemonSet 3 | metadata: 4 | labels: 5 | k8s-app: kube-proxy 6 | name: kube-proxy 7 | namespace: kube-system 8 | spec: 9 | revisionHistoryLimit: 10 10 | selector: 11 | matchLabels: 12 | k8s-app: kube-proxy 13 | template: 14 | metadata: 15 | creationTimestamp: null 16 | labels: 17 | k8s-app: kube-proxy 18 | spec: 19 | containers: 20 | - command: 21 | - /usr/local/bin/kube-proxy 22 | - --config=/var/lib/kube-proxy/config.conf 23 | - --cluster-cidr=10.244.0.0/16 24 | image: gcr.io/google_containers/kube-proxy-amd64:v1.9.7 25 | imagePullPolicy: IfNotPresent 26 | name: kube-proxy 27 | resources: {} 28 | securityContext: 29 | privileged: true 30 | terminationMessagePath: /dev/termination-log 31 | terminationMessagePolicy: File 32 | volumeMounts: 33 | - mountPath: /var/lib/kube-proxy 34 | name: kube-proxy 35 | - mountPath: /run/xtables.lock 36 | name: xtables-lock 37 | - mountPath: /lib/modules 38 | name: lib-modules 39 | readOnly: true 40 | dnsPolicy: ClusterFirst 41 | hostNetwork: true 42 | restartPolicy: Always 43 | schedulerName: default-scheduler 44 | securityContext: {} 45 | serviceAccount: kube-proxy 46 | serviceAccountName: kube-proxy 47 | terminationGracePeriodSeconds: 30 48 | tolerations: 49 | - effect: NoSchedule 50 | key: node-role.kubernetes.io/master 51 | - effect: NoSchedule 52 | key: node.cloudprovider.kubernetes.io/uninitialized 53 | value: "true" 54 | volumes: 55 | - configMap: 56 | defaultMode: 420 57 | name: kube-proxy 58 | name: kube-proxy 59 | - hostPath: 60 | path: /run/xtables.lock 61 | type: FileOrCreate 62 | name: xtables-lock 63 | - hostPath: 64 | path: /lib/modules 65 | type: "" 66 | name: lib-modules 67 | updateStrategy: 68 | rollingUpdate: 69 | maxUnavailable: 1 70 | type: RollingUpdate 71 | -------------------------------------------------------------------------------- /roles/create_network/templates/rbac.yaml: -------------------------------------------------------------------------------- 1 | # Calico Version v3.1.0 2 | # https://docs.projectcalico.org/v3.1/releases#v3.1.0 3 | 4 | --- 5 | 6 | kind: ClusterRole 7 | apiVersion: rbac.authorization.k8s.io/v1beta1 8 | metadata: 9 | name: calico-kube-controllers 10 | rules: 11 | - apiGroups: 12 | - "" 13 | - extensions 14 | resources: 15 | - pods 16 | - namespaces 17 | - networkpolicies 18 | - nodes 19 | verbs: 20 | - watch 21 | - list 22 | - apiGroups: 23 | - networking.k8s.io 24 | resources: 25 | - networkpolicies 26 | verbs: 27 | - watch 28 | - list 29 | --- 30 | kind: ClusterRoleBinding 31 | apiVersion: rbac.authorization.k8s.io/v1beta1 32 | metadata: 33 | name: calico-kube-controllers 34 | roleRef: 35 | apiGroup: rbac.authorization.k8s.io 36 | kind: ClusterRole 37 | name: calico-kube-controllers 38 | subjects: 39 | - kind: ServiceAccount 40 | name: calico-kube-controllers 41 | namespace: kube-system 42 | 43 | --- 44 | 45 | kind: ClusterRole 46 | apiVersion: rbac.authorization.k8s.io/v1beta1 47 | metadata: 48 | name: calico-node 49 | rules: 50 | - apiGroups: [""] 51 | resources: 52 | - pods 53 | - nodes 54 | verbs: 55 | - get 56 | 57 | --- 58 | 59 | apiVersion: rbac.authorization.k8s.io/v1beta1 60 | kind: ClusterRoleBinding 61 | metadata: 62 | name: calico-node 63 | roleRef: 64 | apiGroup: rbac.authorization.k8s.io 65 | kind: ClusterRole 66 | name: calico-node 67 | subjects: 68 | - kind: ServiceAccount 69 | name: calico-node 70 | namespace: kube-system 71 | -------------------------------------------------------------------------------- /roles/etcd/meta/main.yaml: -------------------------------------------------------------------------------- 1 | #dependencies: 2 | # - { role: software } 3 | -------------------------------------------------------------------------------- /roles/etcd/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | - name: install etcd 2 | yum: 3 | name: etcd 4 | state: present 5 | become: yes 6 | 7 | #- name: get ip 8 | # # internal_net is variable in group_vars 9 | # vars: 10 | # ip_list: "{{ ansible_all_ipv4_addresses | ipaddr(internal_net) }}" 11 | # set_fact: 12 | # ip_internal: "{{ ip_list | join('\n') }}" 13 | 14 | - name: mkdir /etc/ssl/etcd 15 | raw: mkdir -p /etc/ssl/etcd 16 | become: yes 17 | 18 | - name: import ssl config 19 | template: src=templates/openssl.cnf.j2 20 | dest="/etc/ssl/etcd/openssl.cnf" 21 | become: yes 22 | 23 | - name: generate ca key 24 | command: openssl genrsa -out ca-key.pem 2048 25 | args: 26 | chdir: /etc/ssl/etcd/ 27 | become: yes 28 | 29 | - name: generate ca cert 30 | command: openssl req -x509 -new -nodes -key ca-key.pem -days 365 -out ca.pem -subj "/CN=etcd-ca" 31 | args: 32 | chdir: /etc/ssl/etcd/ 33 | become: yes 34 | 35 | - name: generate etcd key 36 | command: openssl genrsa -out etcd-key.pem 2048 37 | args: 38 | chdir: /etc/ssl/etcd/ 39 | become: yes 40 | 41 | - name: generate etcd csr 42 | command: openssl req -new -key etcd-key.pem -out etcd.csr -subj "/CN=etcd" -config openssl.cnf 43 | args: 44 | chdir: /etc/ssl/etcd/ 45 | become: yes 46 | 47 | - name: generate etcd cert 48 | command: openssl x509 -req -in etcd.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out etcd.pem -days 365 -extensions v3_req -extfile openssl.cnf 49 | args: 50 | chdir: /etc/ssl/etcd/ 51 | become: yes 52 | 53 | - name: generate etcd-client key 54 | command: openssl genrsa -out etcd-client-key.pem 2048 55 | args: 56 | chdir: /etc/ssl/etcd/ 57 | become: yes 58 | 59 | - name: generate etcd-client csr 60 | command: openssl req -new -key etcd-client-key.pem -out etcd-client.csr -subj "/CN=etcd-client" -config openssl.cnf 61 | args: 62 | chdir: /etc/ssl/etcd/ 63 | become: yes 64 | 65 | - name: generate etcd-client cert 66 | command: openssl x509 -req -in etcd-client.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out etcd-client.pem -days 365 -extensions v3_req -extfile openssl.cnf 67 | args: 68 | chdir: /etc/ssl/etcd/ 69 | become: yes 70 | 71 | - name: import etcd config 72 | template: src=templates/etcd.conf.j2 73 | dest="/etc/etcd/etcd.conf" 74 | become: yes 75 | 76 | - name: clean etcd 77 | raw: rm -rf /var/lib/etcd/* 78 | 79 | - name: Start ETCD service 80 | service: 81 | name: etcd 82 | state: started 83 | enabled: yes 84 | become: yes 85 | -------------------------------------------------------------------------------- /roles/etcd/templates/etcd.conf.j2: -------------------------------------------------------------------------------- 1 | ETCD_NAME="node1" 2 | ETCD_INITIAL_ADVERTISE_PEER_URLS="https://{{ ip_internal }}:2380" 3 | ETCD_LISTEN_PEER_URLS="https://{{ ip_internal }}:2380" 4 | ETCD_LISTEN_CLIENT_URLS="https://{{ ip_internal }}:2379,https://127.0.0.1:2379" 5 | ETCD_ADVERTISE_CLIENT_URLS="https://{{ ip_internal }}:2379" 6 | ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-1" 7 | ETCD_INITIAL_CLUSTER="node1=https://{{ ip_internal }}:2380" 8 | ETCD_INITIAL_CLUSTER_STATE="new" 9 | ETCD_DATA_DIR="/var/lib/etcd/default.etcd" 10 | ETCD_CERT_FILE="/etc/ssl/etcd/etcd-client.pem" 11 | ETCD_KEY_FILE="/etc/ssl/etcd/etcd-client-key.pem" 12 | ETCD_PEER_CERT_FILE="/etc/ssl/etcd/etcd.pem" 13 | ETCD_PEER_KEY_FILE="/etc/ssl/etcd/etcd-key.pem" 14 | ETCD_PEER_CLIENT_CERT_AUTH="true" 15 | ETCD_CLIENT_CERT_AUTH="true" 16 | ETCD_TRUSTED_CA_FILE="/etc/ssl/etcd/ca.pem" 17 | ETCD_PEER_TRUSTED_CA_FILE="/etc/ssl/etcd/ca.pem" 18 | -------------------------------------------------------------------------------- /roles/etcd/templates/openssl.cnf.j2: -------------------------------------------------------------------------------- 1 | [req] 2 | req_extensions = v3_req 3 | distinguished_name = req_distinguished_name 4 | [req_distinguished_name] 5 | [ v3_req ] 6 | basicConstraints = CA:FALSE 7 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment 8 | subjectAltName = @alt_names 9 | [alt_names] 10 | DNS.1 = localhost 11 | IP.1 = 127.0.0.1 12 | IP.2 = {{ ip_internal }} 13 | -------------------------------------------------------------------------------- /roles/helm/files/rbac-config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: tiller 5 | namespace: kube-system 6 | --- 7 | apiVersion: rbac.authorization.k8s.io/v1beta1 8 | kind: ClusterRoleBinding 9 | metadata: 10 | name: tiller 11 | roleRef: 12 | apiGroup: rbac.authorization.k8s.io 13 | kind: ClusterRole 14 | name: cluster-admin 15 | subjects: 16 | - kind: ServiceAccount 17 | name: tiller 18 | namespace: kube-system 19 | -------------------------------------------------------------------------------- /roles/helm/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | - name: Install helm client 2 | become: yes 3 | shell: curl https://raw.githubusercontent.com/kubernetes/helm/v2.9.0/scripts/get > get_helm.sh 4 | 5 | - name: Chmod get_helm.sh 6 | raw: chmod +x get_helm.sh 7 | 8 | - name: Install Helm 9 | raw: ./get_helm.sh 10 | 11 | - name: Create Service Account for tiller 12 | raw: kubectl create serviceaccount tiller --namespace kube-system 13 | 14 | - name: Copy rbac-config.yaml 15 | copy: 16 | src: files/rbac-config.yaml 17 | dest: /tmp/rbac-config.yaml 18 | owner: "{{ ansible_user }}" 19 | group: "{{ ansible_user }}" 20 | mode: 0644 21 | 22 | - name: Create RBAC 23 | raw: kubectl create -f /tmp/rbac-config.yaml 24 | 25 | - name: Helm Init 26 | raw: helm init --service-account tiller 27 | 28 | - name: Sleep 29 | raw: sleep 30 30 | -------------------------------------------------------------------------------- /roles/init_master/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: reset kubeadm 2 | shell: kubeadm reset 3 | become: yes 4 | 5 | - name: copy kubeadm.conf 6 | template: 7 | src: templates/kubeadm.conf.j2 8 | dest: ./kubeadm.conf 9 | owner: root 10 | group: root 11 | mode: 0644 12 | become: yes 13 | 14 | - name: init kubeadm 15 | shell: kubeadm init --config kubeadm.conf 16 | register: kubetoken 17 | become: yes 18 | 19 | - name: Save token "{{ kubetoken.stdout_lines[-1].strip() }}" 20 | local_action: copy content="{{ kubetoken.stdout_lines[-1].strip() }}" dest=./kubetoken 21 | 22 | - name: Create directory $HOME/.kube 23 | shell: mkdir -p $HOME/.kube 24 | 25 | - name: Delete old files for kubectl 26 | shell: rm -rf $HOME/.kube/* 27 | 28 | - name: Get id user 29 | shell: echo "`id -u`:`id -g`" 30 | register: idusergroup 31 | 32 | - name: Get home directory for user 33 | shell: echo $HOME 34 | register: homeuser 35 | 36 | - name: Copy cert for kubectl 37 | shell: cp -i /etc/kubernetes/admin.conf {{ homeuser.stdout_lines[0] }}/.kube/config 38 | become: yes 39 | 40 | - name: Chown for cert 41 | shell: chown {{ idusergroup.stdout_lines[0] }} {{ homeuser.stdout_lines[0] }}/.kube/config 42 | become: yes 43 | -------------------------------------------------------------------------------- /roles/init_master/templates/kubeadm.conf.j2: -------------------------------------------------------------------------------- 1 | apiVersion: kubeadm.k8s.io/v1alpha1 2 | kind: MasterConfiguration 3 | api: 4 | advertiseAddress: {{ ip_internal }} 5 | bindPort: 6443 6 | etcd: 7 | endpoints: 8 | - https://{{ ip_internal }}:2379 9 | caFile: /etc/ssl/etcd/ca.pem 10 | certFile: /etc/ssl/etcd/etcd-client.pem 11 | keyFile: /etc/ssl/etcd/etcd-client-key.pem 12 | apiServerCertSANs: 13 | - 127.0.0.1 14 | - {{ ip_internal }} 15 | networking: 16 | serviceSubnet: 10.96.0.0/12 17 | podSubnet: 10.244.0.0/16 18 | -------------------------------------------------------------------------------- /roles/init_slave/meta/main.yaml: -------------------------------------------------------------------------------- 1 | #dependencies: 2 | # - { role: init_master } 3 | -------------------------------------------------------------------------------- /roles/init_slave/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | - name: Reset kubeadm 2 | shell: kubeadm reset 3 | become: yes 4 | 5 | # fix me later 6 | #- name: Join kubeadm 7 | # shell: "{% for host in groups['masters'] %}{{ hostvars[host]['join_command'] }}{% endfor %}" 8 | # become: yes 9 | 10 | - name: Delete /etc/kubernetes 11 | raw: rm /etc/kubernetes/ -rf 12 | become: yes 13 | 14 | - name: Join kubeadm 15 | raw: "{{ kubetoken }}" 16 | become: yes 17 | vars: 18 | kubetoken: "{{ lookup('file', 'kubetoken') }}" -------------------------------------------------------------------------------- /roles/reboot/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | - name: reboot host 2 | shell: nohup bash -c "sleep 4; systemctl reboot" & 3 | async: 0 4 | poll: 0 5 | ignore_errors: yes 6 | become: yes 7 | tags: 8 | - reboot 9 | -------------------------------------------------------------------------------- /roles/selinux/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | - name: Disable selinux 2 | lineinfile: 3 | destfile: /etc/selinux/config 4 | regexp: '^SELINUX=' 5 | line: 'SELINUX=disabled' 6 | become: yes 7 | tags: 8 | - selinux 9 | 10 | - name: swap off 11 | raw: swapoff -a -------------------------------------------------------------------------------- /roles/software/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | - name: include epel-release 2 | become: yes 3 | yum: 4 | name: epel-release 5 | state: present 6 | when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' 7 | tags: 8 | - packages 9 | 10 | 11 | - name: install convenience packages 12 | become: yes 13 | yum: 14 | name: "{{ item }}" 15 | state: present 16 | with_items: 17 | - htop 18 | - vim 19 | - lsof 20 | - strace 21 | - yum-plugin-versionlock 22 | - ncdu 23 | tags: 24 | - packages 25 | 26 | 27 | - name: add kubernetes repo 28 | become: yes 29 | yum_repository: 30 | name: Kubernetes 31 | description: Kubernetes Repository 32 | file: kubernetes 33 | baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-$basearch 34 | enabled: yes 35 | gpgcheck: yes 36 | repo_gpgcheck: yes 37 | gpgkey: https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg 38 | tags: 39 | - packages 40 | 41 | 42 | - name: add docker-ce-stable repo 43 | become: yes 44 | yum_repository: 45 | name: docker-ce-stable 46 | description: docker-ce stable repo 47 | file: docker-ce-stable 48 | baseurl: https://download.docker.com/linux/centos/7/$basearch/stable 49 | enabled: yes 50 | gpgcheck: yes 51 | repo_gpgcheck: yes 52 | gpgkey: https://download.docker.com/linux/centos/gpg 53 | tags: 54 | - packages 55 | 56 | 57 | - name: upgrade all packages 58 | become: yes 59 | yum: 60 | name: '*' 61 | state: latest 62 | tags: 63 | - packages 64 | 65 | 66 | - name: install docker & kubernetes 67 | become: yes 68 | yum: 69 | name: "{{ item }}" 70 | state: present 71 | with_items: 72 | - docker-ce-17.12.1.ce 73 | - kubelet-1.9.7 74 | - kubeadm-1.9.7 75 | - kubectl-1.9.7 76 | tags: 77 | - packages 78 | 79 | 80 | - name: versionlock docker & kubernetes 81 | become: yes 82 | shell: yum versionlock add kubelet-1.9.7 kubectl-1.9.7 kubeadm-1.9.7 docker-ce-17.12.1.ce 83 | tags: 84 | - packages 85 | 86 | # only for centos >>> 87 | - name: Change cgroup-driver in kubelet 88 | replace: 89 | dest: /etc/systemd/system/kubelet.service.d/10-kubeadm.conf 90 | regexp: 'cgroup-driver=systemd' 91 | replace: 'cgroup-driver=cgroupfs' 92 | become: yes 93 | 94 | - name: copy /etc/sysctl.d/k8s.conf 95 | copy: 96 | src: templates/k8s.conf 97 | dest: /etc/sysctl.d/k8s.conf 98 | owner: root 99 | group: root 100 | mode: 0644 101 | become: yes 102 | 103 | - name: set sysctl config 104 | raw: 'sysctl --system' 105 | become: yes 106 | # <<< 107 | 108 | - name: Start docker service 109 | service: 110 | name: docker 111 | state: started 112 | enabled: yes 113 | become: yes 114 | 115 | 116 | - name: Start kubelet service 117 | service: 118 | name: kubelet 119 | state: started 120 | enabled: yes 121 | become: yes 122 | 123 | -------------------------------------------------------------------------------- /roles/software/templates/k8s.conf: -------------------------------------------------------------------------------- 1 | net.bridge.bridge-nf-call-ip6tables = 1 2 | net.bridge.bridge-nf-call-iptables = 1 3 | --------------------------------------------------------------------------------