From 38ae2f0a21e6e3934ffba5136bf1f4bb39ab5800 Mon Sep 17 00:00:00 2001 From: apavanello Date: Wed, 18 Dec 2019 10:20:53 -0300 Subject: [PATCH 1/6] (Feat) ADD CENTOS CONFIG --- install_k8s_centos/hosts | 9 ++++ install_k8s_centos/main.yml | 46 ++++++++++++++++ .../roles/create-cluster/README.md | 38 +++++++++++++ .../roles/create-cluster/defaults/main.yml | 2 + .../roles/create-cluster/handlers/main.yml | 2 + .../roles/create-cluster/meta/main.yml | 53 +++++++++++++++++++ .../create-cluster/tasks/init-cluster.yml | 37 +++++++++++++ .../roles/create-cluster/tasks/main.yml | 3 ++ .../roles/create-cluster/tests/inventory | 2 + .../roles/create-cluster/tests/test.yml | 5 ++ .../roles/create-cluster/vars/main.yml | 3 ++ .../roles/install-k8s/README.md | 38 +++++++++++++ .../roles/install-k8s/defaults/main.yml | 2 + .../roles/install-k8s/handlers/main.yml | 2 + .../roles/install-k8s/meta/main.yml | 53 +++++++++++++++++++ .../roles/install-k8s/tasks/install.yml | 28 ++++++++++ .../roles/install-k8s/tasks/main.yml | 3 ++ .../roles/install-k8s/tests/inventory | 2 + .../roles/install-k8s/tests/test.yml | 5 ++ .../roles/install-k8s/vars/main.yml | 2 + .../roles/join-workers/README.md | 38 +++++++++++++ .../roles/join-workers/defaults/main.yml | 2 + .../roles/join-workers/handlers/main.yml | 2 + .../roles/join-workers/meta/main.yml | 53 +++++++++++++++++++ .../roles/join-workers/tasks/join-cluster.yml | 19 +++++++ .../roles/join-workers/tasks/main.yml | 3 ++ .../roles/join-workers/tests/inventory | 2 + .../roles/join-workers/tests/test.yml | 5 ++ .../roles/join-workers/vars/main.yml | 2 + 29 files changed, 461 insertions(+) create mode 100644 install_k8s_centos/hosts create mode 100644 install_k8s_centos/main.yml create mode 100644 install_k8s_centos/roles/create-cluster/README.md create mode 100644 install_k8s_centos/roles/create-cluster/defaults/main.yml create mode 100644 install_k8s_centos/roles/create-cluster/handlers/main.yml create mode 100644 install_k8s_centos/roles/create-cluster/meta/main.yml create mode 100644 install_k8s_centos/roles/create-cluster/tasks/init-cluster.yml create mode 100644 install_k8s_centos/roles/create-cluster/tasks/main.yml create mode 100644 install_k8s_centos/roles/create-cluster/tests/inventory create mode 100644 install_k8s_centos/roles/create-cluster/tests/test.yml create mode 100644 install_k8s_centos/roles/create-cluster/vars/main.yml create mode 100644 install_k8s_centos/roles/install-k8s/README.md create mode 100644 install_k8s_centos/roles/install-k8s/defaults/main.yml create mode 100644 install_k8s_centos/roles/install-k8s/handlers/main.yml create mode 100644 install_k8s_centos/roles/install-k8s/meta/main.yml create mode 100644 install_k8s_centos/roles/install-k8s/tasks/install.yml create mode 100644 install_k8s_centos/roles/install-k8s/tasks/main.yml create mode 100644 install_k8s_centos/roles/install-k8s/tests/inventory create mode 100644 install_k8s_centos/roles/install-k8s/tests/test.yml create mode 100644 install_k8s_centos/roles/install-k8s/vars/main.yml create mode 100644 install_k8s_centos/roles/join-workers/README.md create mode 100644 install_k8s_centos/roles/join-workers/defaults/main.yml create mode 100644 install_k8s_centos/roles/join-workers/handlers/main.yml create mode 100644 install_k8s_centos/roles/join-workers/meta/main.yml create mode 100644 install_k8s_centos/roles/join-workers/tasks/join-cluster.yml create mode 100644 install_k8s_centos/roles/join-workers/tasks/main.yml create mode 100644 install_k8s_centos/roles/join-workers/tests/inventory create mode 100644 install_k8s_centos/roles/join-workers/tests/test.yml create mode 100644 install_k8s_centos/roles/join-workers/vars/main.yml diff --git a/install_k8s_centos/hosts b/install_k8s_centos/hosts new file mode 100644 index 0000000..b570369 --- /dev/null +++ b/install_k8s_centos/hosts @@ -0,0 +1,9 @@ +[k8s-master] + + +[k8s-workers] + + +[k8s-workers:vars] +K8S_MASTER_NODE_IP= +K8S_API_SECURE_PORT=6443 diff --git a/install_k8s_centos/main.yml b/install_k8s_centos/main.yml new file mode 100644 index 0000000..b146ad3 --- /dev/null +++ b/install_k8s_centos/main.yml @@ -0,0 +1,46 @@ +- hosts: all + become: yes + user: centos + gather_facts: no + pre_tasks: + - name: desativando o SeLinux + selinux: + state: disabled + + - name: desativando o Firewalld + yum: + name: firewalld + state: removed + + - name: desativando o swap + shell: swapoff -a + + - name: removendo o swap + replace: + path: /etc/fstab + regexp: '^([^#].*?\sswap\s+sw\s+.*)$' + replace: '# \1' + + - name: 'atualizando repo' + yum: + update_only: latest + + - name: 'instalando o python' + yum: + name: python + state: latest + + roles: + - { role: install-k8s, tags: ["install_k8s_role"]} + +- hosts: k8s-master + become: yes + user: centos + roles: + - { role: create-cluster, tags: ["create_cluster_role"]} + +- hosts: k8s-workers + become: yes + user: centos + roles: + - { role: join-workers, tags: ["join_workers_role"]} diff --git a/install_k8s_centos/roles/create-cluster/README.md b/install_k8s_centos/roles/create-cluster/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/install_k8s_centos/roles/create-cluster/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/install_k8s_centos/roles/create-cluster/defaults/main.yml b/install_k8s_centos/roles/create-cluster/defaults/main.yml new file mode 100644 index 0000000..53be71b --- /dev/null +++ b/install_k8s_centos/roles/create-cluster/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for create-cluster \ No newline at end of file diff --git a/install_k8s_centos/roles/create-cluster/handlers/main.yml b/install_k8s_centos/roles/create-cluster/handlers/main.yml new file mode 100644 index 0000000..ccb7e14 --- /dev/null +++ b/install_k8s_centos/roles/create-cluster/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for create-cluster \ No newline at end of file diff --git a/install_k8s_centos/roles/create-cluster/meta/main.yml b/install_k8s_centos/roles/create-cluster/meta/main.yml new file mode 100644 index 0000000..3a212a9 --- /dev/null +++ b/install_k8s_centos/roles/create-cluster/meta/main.yml @@ -0,0 +1,53 @@ +galaxy_info: + author: your name + description: your description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.4 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. + \ No newline at end of file diff --git a/install_k8s_centos/roles/create-cluster/tasks/init-cluster.yml b/install_k8s_centos/roles/create-cluster/tasks/init-cluster.yml new file mode 100644 index 0000000..44b274f --- /dev/null +++ b/install_k8s_centos/roles/create-cluster/tasks/init-cluster.yml @@ -0,0 +1,37 @@ +- name: Reset Cluster + command: + kubeadm reset --force + register: kubeadmin_init +- name: Initialize Kubernetes master with kubeadm init. + command: + kubeadm init + register: kubeadmin_init +- name: Ensure .kube directory exists. + file: + path: ~/.kube + state: directory +- name: Symlink the kubectl admin.conf to ~/.kube/conf. + file: + src: /etc/kubernetes/admin.conf + dest: ~/.kube/config + state: link +- name: Configure weavenet networking. + shell: kubectl apply -f {{ default_kubernetes_cni_weavenet_manifestUrl }} + register: weavenet_result +- name: "Cluster token" + shell: kubeadm token list | cut -d ' ' -f1 | sed -n '2p' + register: K8S_TOKEN +- name: "CA Hash" + shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //' + register: K8S_MASTER_CA_HASH +- name: "Add K8S Token and Hash to dummy host" + add_host: + name: "K8S_TOKEN_HOLDER" + token: "{{ K8S_TOKEN.stdout }}" + hash: "{{ K8S_MASTER_CA_HASH.stdout }}" +- name: + debug: + msg: "[Master] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}" +- name: + debug: + msg: "[Master] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}" diff --git a/install_k8s_centos/roles/create-cluster/tasks/main.yml b/install_k8s_centos/roles/create-cluster/tasks/main.yml new file mode 100644 index 0000000..e20137c --- /dev/null +++ b/install_k8s_centos/roles/create-cluster/tasks/main.yml @@ -0,0 +1,3 @@ +--- +# tasks file for create-cluster +- include: init-cluster.yml diff --git a/install_k8s_centos/roles/create-cluster/tests/inventory b/install_k8s_centos/roles/create-cluster/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/install_k8s_centos/roles/create-cluster/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/install_k8s_centos/roles/create-cluster/tests/test.yml b/install_k8s_centos/roles/create-cluster/tests/test.yml new file mode 100644 index 0000000..2cca844 --- /dev/null +++ b/install_k8s_centos/roles/create-cluster/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - create-cluster \ No newline at end of file diff --git a/install_k8s_centos/roles/create-cluster/vars/main.yml b/install_k8s_centos/roles/create-cluster/vars/main.yml new file mode 100644 index 0000000..dd326c7 --- /dev/null +++ b/install_k8s_centos/roles/create-cluster/vars/main.yml @@ -0,0 +1,3 @@ +--- +# vars file for create-cluster +default_kubernetes_cni_weavenet_manifestUrl: "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')" diff --git a/install_k8s_centos/roles/install-k8s/README.md b/install_k8s_centos/roles/install-k8s/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/install_k8s_centos/roles/install-k8s/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/install_k8s_centos/roles/install-k8s/defaults/main.yml b/install_k8s_centos/roles/install-k8s/defaults/main.yml new file mode 100644 index 0000000..6066d8a --- /dev/null +++ b/install_k8s_centos/roles/install-k8s/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for install-k8s \ No newline at end of file diff --git a/install_k8s_centos/roles/install-k8s/handlers/main.yml b/install_k8s_centos/roles/install-k8s/handlers/main.yml new file mode 100644 index 0000000..88c0fef --- /dev/null +++ b/install_k8s_centos/roles/install-k8s/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for install-k8s \ No newline at end of file diff --git a/install_k8s_centos/roles/install-k8s/meta/main.yml b/install_k8s_centos/roles/install-k8s/meta/main.yml new file mode 100644 index 0000000..3a212a9 --- /dev/null +++ b/install_k8s_centos/roles/install-k8s/meta/main.yml @@ -0,0 +1,53 @@ +galaxy_info: + author: your name + description: your description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.4 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. + \ No newline at end of file diff --git a/install_k8s_centos/roles/install-k8s/tasks/install.yml b/install_k8s_centos/roles/install-k8s/tasks/install.yml new file mode 100644 index 0000000..b087aa7 --- /dev/null +++ b/install_k8s_centos/roles/install-k8s/tasks/install.yml @@ -0,0 +1,28 @@ +- name: Adicionando o Repositorio do Docker + shell: curl -fSsl https://download.docker.com/linux/centos/docker-ce.repo > /etc/yum.repos.d/docker-ce.repo + +- name: Instalando o Docker + yum: + name: docker-ce + state: latest + +- name: Adicionando o repo do k8s + yum_repository: + name: kubernetes.repo + baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 + gpgcheck: yes + repo_gpgcheck: yes + gpgkey: + - https://packages.cloud.google.com/yum/doc/yum-key.gpg + - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg + enabled: yes + state: present + +- name: Install k8s packages + apt: + name: "{{ packages }}" + vars: + packages: + - kubelet + - kubeadm + - kubectl diff --git a/install_k8s_centos/roles/install-k8s/tasks/main.yml b/install_k8s_centos/roles/install-k8s/tasks/main.yml new file mode 100644 index 0000000..518fd2a --- /dev/null +++ b/install_k8s_centos/roles/install-k8s/tasks/main.yml @@ -0,0 +1,3 @@ +--- +# tasks file for install-k8s +- include: install.yml diff --git a/install_k8s_centos/roles/install-k8s/tests/inventory b/install_k8s_centos/roles/install-k8s/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/install_k8s_centos/roles/install-k8s/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/install_k8s_centos/roles/install-k8s/tests/test.yml b/install_k8s_centos/roles/install-k8s/tests/test.yml new file mode 100644 index 0000000..7491ccc --- /dev/null +++ b/install_k8s_centos/roles/install-k8s/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - install-k8s \ No newline at end of file diff --git a/install_k8s_centos/roles/install-k8s/vars/main.yml b/install_k8s_centos/roles/install-k8s/vars/main.yml new file mode 100644 index 0000000..e4baa9e --- /dev/null +++ b/install_k8s_centos/roles/install-k8s/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for install-k8s \ No newline at end of file diff --git a/install_k8s_centos/roles/join-workers/README.md b/install_k8s_centos/roles/join-workers/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/install_k8s_centos/roles/join-workers/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/install_k8s_centos/roles/join-workers/defaults/main.yml b/install_k8s_centos/roles/join-workers/defaults/main.yml new file mode 100644 index 0000000..c4cc343 --- /dev/null +++ b/install_k8s_centos/roles/join-workers/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for join-workers \ No newline at end of file diff --git a/install_k8s_centos/roles/join-workers/handlers/main.yml b/install_k8s_centos/roles/join-workers/handlers/main.yml new file mode 100644 index 0000000..7d3bb5b --- /dev/null +++ b/install_k8s_centos/roles/join-workers/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for join-workers \ No newline at end of file diff --git a/install_k8s_centos/roles/join-workers/meta/main.yml b/install_k8s_centos/roles/join-workers/meta/main.yml new file mode 100644 index 0000000..3a212a9 --- /dev/null +++ b/install_k8s_centos/roles/join-workers/meta/main.yml @@ -0,0 +1,53 @@ +galaxy_info: + author: your name + description: your description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.4 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. + \ No newline at end of file diff --git a/install_k8s_centos/roles/join-workers/tasks/join-cluster.yml b/install_k8s_centos/roles/join-workers/tasks/join-cluster.yml new file mode 100644 index 0000000..8fc172a --- /dev/null +++ b/install_k8s_centos/roles/join-workers/tasks/join-cluster.yml @@ -0,0 +1,19 @@ +- name: + debug: + msg: "[Worker] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}" + +- name: + debug: + msg: "[Worker] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}" + +- name: "Kubeadm reset node cluster config" + command: + kubeadm reset --force + register: kubeadm_reset_node + +- name: "Kubeadm join" + shell: + kubeadm join --token={{ hostvars['K8S_TOKEN_HOLDER']['token'] }} + --discovery-token-ca-cert-hash sha256:{{ hostvars['K8S_TOKEN_HOLDER']['hash'] }} + {{K8S_MASTER_NODE_IP}}:{{K8S_API_SECURE_PORT}} + diff --git a/install_k8s_centos/roles/join-workers/tasks/main.yml b/install_k8s_centos/roles/join-workers/tasks/main.yml new file mode 100644 index 0000000..037253a --- /dev/null +++ b/install_k8s_centos/roles/join-workers/tasks/main.yml @@ -0,0 +1,3 @@ +--- +# tasks file for join-workers +- include: join-cluster.yml diff --git a/install_k8s_centos/roles/join-workers/tests/inventory b/install_k8s_centos/roles/join-workers/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/install_k8s_centos/roles/join-workers/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/install_k8s_centos/roles/join-workers/tests/test.yml b/install_k8s_centos/roles/join-workers/tests/test.yml new file mode 100644 index 0000000..ed217da --- /dev/null +++ b/install_k8s_centos/roles/join-workers/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - join-workers \ No newline at end of file diff --git a/install_k8s_centos/roles/join-workers/vars/main.yml b/install_k8s_centos/roles/join-workers/vars/main.yml new file mode 100644 index 0000000..d95c62c --- /dev/null +++ b/install_k8s_centos/roles/join-workers/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for join-workers \ No newline at end of file From 40e09534a42ef50eacf69249145b006d680b553a Mon Sep 17 00:00:00 2001 From: apavanello Date: Wed, 18 Dec 2019 10:38:19 -0300 Subject: [PATCH 2/6] (FIX) RAW no arquivo main principal --- install_k8s_centos/main.yml | 25 ++----------------- .../roles/install-k8s/tasks/install.yml | 18 +++++++++++++ 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/install_k8s_centos/main.yml b/install_k8s_centos/main.yml index b146ad3..3a51ccb 100644 --- a/install_k8s_centos/main.yml +++ b/install_k8s_centos/main.yml @@ -3,32 +3,11 @@ user: centos gather_facts: no pre_tasks: - - name: desativando o SeLinux - selinux: - state: disabled - - - name: desativando o Firewalld - yum: - name: firewalld - state: removed - - - name: desativando o swap - shell: swapoff -a - - - name: removendo o swap - replace: - path: /etc/fstab - regexp: '^([^#].*?\sswap\s+sw\s+.*)$' - replace: '# \1' - - name: 'atualizando repo' - yum: - update_only: latest + raw: yum update -y - name: 'instalando o python' - yum: - name: python - state: latest + raw: yum install python -y roles: - { role: install-k8s, tags: ["install_k8s_role"]} diff --git a/install_k8s_centos/roles/install-k8s/tasks/install.yml b/install_k8s_centos/roles/install-k8s/tasks/install.yml index b087aa7..2d1e243 100644 --- a/install_k8s_centos/roles/install-k8s/tasks/install.yml +++ b/install_k8s_centos/roles/install-k8s/tasks/install.yml @@ -1,3 +1,21 @@ +- name: desativando o SeLinux + selinux: + state: disabled + +- name: desativando o Firewalld + yum: + name: firewalld + state: removed + +- name: desativando o swap + shell: swapoff -a + +- name: removendo o swap + replace: + path: /etc/fstab + regexp: '^([^#].*?\sswap\s+sw\s+.*)$' + replace: '# \1' + - name: Adicionando o Repositorio do Docker shell: curl -fSsl https://download.docker.com/linux/centos/docker-ce.repo > /etc/yum.repos.d/docker-ce.repo From cbfd3f94a075a18a825da5366ddc57b23dc3a1cc Mon Sep 17 00:00:00 2001 From: apavanello Date: Wed, 18 Dec 2019 11:23:08 -0300 Subject: [PATCH 3/6] (fix) Tiny Fixes --- install_k8s_centos/main.yml | 2 +- .../roles/install-k8s/tasks/install.yml | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/install_k8s_centos/main.yml b/install_k8s_centos/main.yml index 3a51ccb..bbaf68f 100644 --- a/install_k8s_centos/main.yml +++ b/install_k8s_centos/main.yml @@ -7,7 +7,7 @@ raw: yum update -y - name: 'instalando o python' - raw: yum install python -y + raw: yum install python2 python -y roles: - { role: install-k8s, tags: ["install_k8s_role"]} diff --git a/install_k8s_centos/roles/install-k8s/tasks/install.yml b/install_k8s_centos/roles/install-k8s/tasks/install.yml index 2d1e243..7c792e3 100644 --- a/install_k8s_centos/roles/install-k8s/tasks/install.yml +++ b/install_k8s_centos/roles/install-k8s/tasks/install.yml @@ -16,6 +16,16 @@ regexp: '^([^#].*?\sswap\s+sw\s+.*)$' replace: '# \1' +- name: Permitindo o Forward no Centos + shell: echo 1 > /proc/sys/net/ipv4/ip_forward + +- name: gravando o forward persistente a reinicios + sysctl: + name: net.ipv4.ip_forward + reload: yes + state: present + value: '1' + - name: Adicionando o Repositorio do Docker shell: curl -fSsl https://download.docker.com/linux/centos/docker-ce.repo > /etc/yum.repos.d/docker-ce.repo @@ -24,7 +34,7 @@ name: docker-ce state: latest -- name: Adicionando o repo do k8s +- name: Adicionando o repo do k8s no YUM yum_repository: name: kubernetes.repo baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 @@ -37,10 +47,10 @@ state: present - name: Install k8s packages - apt: + yum: name: "{{ packages }}" vars: packages: - kubelet - kubeadm - - kubectl + - kubectl \ No newline at end of file From 9ce6e84ca91486bad861b527fabe54c3d5bebf65 Mon Sep 17 00:00:00 2001 From: apavanello Date: Wed, 18 Dec 2019 11:53:37 -0300 Subject: [PATCH 4/6] (fix) minor Fixes --- install_k8s_centos/hosts | 7 ++++--- install_k8s_centos/main.retry | 3 +++ install_k8s_centos/main.yml | 6 +++--- .../roles/create-cluster/tasks/init-cluster.yml | 4 ++-- .../roles/install-k8s/tasks/install.yml | 15 +++++++++++++-- 5 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 install_k8s_centos/main.retry diff --git a/install_k8s_centos/hosts b/install_k8s_centos/hosts index b570369..6ce3c18 100644 --- a/install_k8s_centos/hosts +++ b/install_k8s_centos/hosts @@ -1,9 +1,10 @@ [k8s-master] - +172.16.9.112 [k8s-workers] - +172.16.9.113 +172.16.9.114 [k8s-workers:vars] -K8S_MASTER_NODE_IP= +K8S_MASTER_NODE_IP=172.16.9.112 K8S_API_SECURE_PORT=6443 diff --git a/install_k8s_centos/main.retry b/install_k8s_centos/main.retry new file mode 100644 index 0000000..3809d2d --- /dev/null +++ b/install_k8s_centos/main.retry @@ -0,0 +1,3 @@ +172.16.9.112 +172.16.9.113 +172.16.9.114 diff --git a/install_k8s_centos/main.yml b/install_k8s_centos/main.yml index bbaf68f..3aeb6a1 100644 --- a/install_k8s_centos/main.yml +++ b/install_k8s_centos/main.yml @@ -1,6 +1,6 @@ - hosts: all become: yes - user: centos + user: apavanello gather_facts: no pre_tasks: - name: 'atualizando repo' @@ -14,12 +14,12 @@ - hosts: k8s-master become: yes - user: centos + user: apavanello roles: - { role: create-cluster, tags: ["create_cluster_role"]} - hosts: k8s-workers become: yes - user: centos + user: apavanello roles: - { role: join-workers, tags: ["join_workers_role"]} diff --git a/install_k8s_centos/roles/create-cluster/tasks/init-cluster.yml b/install_k8s_centos/roles/create-cluster/tasks/init-cluster.yml index 44b274f..5d297ec 100644 --- a/install_k8s_centos/roles/create-cluster/tasks/init-cluster.yml +++ b/install_k8s_centos/roles/create-cluster/tasks/init-cluster.yml @@ -29,9 +29,9 @@ name: "K8S_TOKEN_HOLDER" token: "{{ K8S_TOKEN.stdout }}" hash: "{{ K8S_MASTER_CA_HASH.stdout }}" -- name: +- name: '' debug: msg: "[Master] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}" -- name: +- name: '' debug: msg: "[Master] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}" diff --git a/install_k8s_centos/roles/install-k8s/tasks/install.yml b/install_k8s_centos/roles/install-k8s/tasks/install.yml index 7c792e3..6be5641 100644 --- a/install_k8s_centos/roles/install-k8s/tasks/install.yml +++ b/install_k8s_centos/roles/install-k8s/tasks/install.yml @@ -7,6 +7,11 @@ name: firewalld state: removed +- name: instalando o iptables + yum: + name: iptables + state: present + - name: desativando o swap shell: swapoff -a @@ -34,15 +39,21 @@ name: docker-ce state: latest +- name: iniciando o servico do Docker + systemd: + name: docker + state: started + - name: Adicionando o repo do k8s no YUM yum_repository: name: kubernetes.repo + description: 'Repositorio do Kubernetes para Centos7' baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 gpgcheck: yes repo_gpgcheck: yes gpgkey: - - https://packages.cloud.google.com/yum/doc/yum-key.gpg - - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg + https://packages.cloud.google.com/yum/doc/yum-key.gpg + https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg enabled: yes state: present From 290e18a9ca527c8a54a5ee69e3709689c94b2c83 Mon Sep 17 00:00:00 2001 From: apavanello Date: Wed, 18 Dec 2019 12:32:03 -0300 Subject: [PATCH 5/6] (FIX) Major fix - erro nas chave gpg do k8s --- .../roles/install-k8s/tasks/install.yml | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/install_k8s_centos/roles/install-k8s/tasks/install.yml b/install_k8s_centos/roles/install-k8s/tasks/install.yml index 6be5641..265e91f 100644 --- a/install_k8s_centos/roles/install-k8s/tasks/install.yml +++ b/install_k8s_centos/roles/install-k8s/tasks/install.yml @@ -34,6 +34,20 @@ - name: Adicionando o Repositorio do Docker shell: curl -fSsl https://download.docker.com/linux/centos/docker-ce.repo > /etc/yum.repos.d/docker-ce.repo +- name: Adicionando o repo do kubernetes no YUM + yum_repository: + name: kubernetes + file: kubernetes + description: kubernetes + baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 + gpgcheck: yes + repo_gpgcheck: yes + gpgkey: + - https://packages.cloud.google.com/yum/doc/yum-key.gpg + - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg + enabled: yes + state: present + - name: Instalando o Docker yum: name: docker-ce @@ -44,19 +58,6 @@ name: docker state: started -- name: Adicionando o repo do k8s no YUM - yum_repository: - name: kubernetes.repo - description: 'Repositorio do Kubernetes para Centos7' - baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 - gpgcheck: yes - repo_gpgcheck: yes - gpgkey: - https://packages.cloud.google.com/yum/doc/yum-key.gpg - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg - enabled: yes - state: present - - name: Install k8s packages yum: name: "{{ packages }}" From e02529cbd6390be2c73d4ca2c15b5544a667334b Mon Sep 17 00:00:00 2001 From: apavanello Date: Wed, 18 Dec 2019 12:33:58 -0300 Subject: [PATCH 6/6] (MRG) Merge from Testes --- install_k8s_centos/hosts | 7 +++---- install_k8s_centos/main.retry | 3 --- install_k8s_centos/main.yml | 6 +++--- 3 files changed, 6 insertions(+), 10 deletions(-) delete mode 100644 install_k8s_centos/main.retry diff --git a/install_k8s_centos/hosts b/install_k8s_centos/hosts index 6ce3c18..b570369 100644 --- a/install_k8s_centos/hosts +++ b/install_k8s_centos/hosts @@ -1,10 +1,9 @@ [k8s-master] -172.16.9.112 + [k8s-workers] -172.16.9.113 -172.16.9.114 + [k8s-workers:vars] -K8S_MASTER_NODE_IP=172.16.9.112 +K8S_MASTER_NODE_IP= K8S_API_SECURE_PORT=6443 diff --git a/install_k8s_centos/main.retry b/install_k8s_centos/main.retry deleted file mode 100644 index 3809d2d..0000000 --- a/install_k8s_centos/main.retry +++ /dev/null @@ -1,3 +0,0 @@ -172.16.9.112 -172.16.9.113 -172.16.9.114 diff --git a/install_k8s_centos/main.yml b/install_k8s_centos/main.yml index 3aeb6a1..bbaf68f 100644 --- a/install_k8s_centos/main.yml +++ b/install_k8s_centos/main.yml @@ -1,6 +1,6 @@ - hosts: all become: yes - user: apavanello + user: centos gather_facts: no pre_tasks: - name: 'atualizando repo' @@ -14,12 +14,12 @@ - hosts: k8s-master become: yes - user: apavanello + user: centos roles: - { role: create-cluster, tags: ["create_cluster_role"]} - hosts: k8s-workers become: yes - user: apavanello + user: centos roles: - { role: join-workers, tags: ["join_workers_role"]}