From 6d3c84aca5359afa58bbbd5c8b2b644f64b8dffc Mon Sep 17 00:00:00 2001 From: ss75710541 <75710541@qq.com> Date: Mon, 21 Feb 2022 11:10:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20add=20node=20=E6=94=AF=E6=8C=81ubun?= =?UTF-8?q?tu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible.hosts.ha.publicnetwork.tpl | 3 ++ ansible.hosts.ha.tpl | 3 ++ ansible.hosts.ha.vip.tpl | 3 ++ ansible.hosts.tpl | 13 +++++---- roles/host-init/tasks/apt.yml | 36 ++++++++++++++++++++++++ roles/host-init/tasks/docker.yml | 29 +++++++++++++++++++ roles/host-init/tasks/installKubeadm.yml | 13 +++++++++ roles/host-init/tasks/ipvs.yml | 12 ++++++++ roles/host-init/tasks/main.yml | 8 +++++- roles/host-init/tasks/resolvUbuntu.yml | 11 ++++++++ roles/host-init/tasks/update.yml | 6 ++++ 11 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 roles/host-init/tasks/apt.yml create mode 100644 roles/host-init/tasks/resolvUbuntu.yml diff --git a/ansible.hosts.ha.publicnetwork.tpl b/ansible.hosts.ha.publicnetwork.tpl index 7e473c9..95a574b 100644 --- a/ansible.hosts.ha.publicnetwork.tpl +++ b/ansible.hosts.ha.publicnetwork.tpl @@ -49,6 +49,9 @@ pod_subnet=10.128.0.0/16 helm_binary_md5=e4500993ba21e5e6bdfbc084b4342025 helm_binary_url=https://pnode.solarfs.io/dn/file/{{helm_binary_md5}}/helm-v3.6.0-linux-amd64.tar.gz +# os id, centos|ubuntu +OS_ID="centos" + [install] master1.solarfs.k8s diff --git a/ansible.hosts.ha.tpl b/ansible.hosts.ha.tpl index 48ed479..d4ece8d 100644 --- a/ansible.hosts.ha.tpl +++ b/ansible.hosts.ha.tpl @@ -49,6 +49,9 @@ pod_subnet=10.128.0.0/16 helm_binary_md5=e4500993ba21e5e6bdfbc084b4342025 helm_binary_url=https://pnode.solarfs.io/dn/file/{{helm_binary_md5}}/helm-v3.6.0-linux-amd64.tar.gz +# os id, centos|ubuntu +OS_ID="centos" + [install] master1.solarfs.k8s diff --git a/ansible.hosts.ha.vip.tpl b/ansible.hosts.ha.vip.tpl index a274caa..63906b3 100644 --- a/ansible.hosts.ha.vip.tpl +++ b/ansible.hosts.ha.vip.tpl @@ -62,6 +62,9 @@ ingress_nodeport_https=32443 helm_binary_md5=e4500993ba21e5e6bdfbc084b4342025 helm_binary_url=https://pnode.solarfs.io/dn/file/{{helm_binary_md5}}/helm-v3.6.0-linux-amd64.tar.gz +# os id, centos|ubuntu +OS_ID="centos" + [install] master1.solarfs.k8s diff --git a/ansible.hosts.tpl b/ansible.hosts.tpl index a855387..5fadc34 100644 --- a/ansible.hosts.tpl +++ b/ansible.hosts.tpl @@ -50,15 +50,18 @@ pod_subnet=10.128.0.0/16 helm_binary_md5=24b16800f8c7f44b5dd128e3355ecf1b helm_binary_url=https://pnode.solarfs.io/dn/file/{{helm_binary_md5}}/helm-v3.6.3-linux-amd64.tar.gz +# os id, centos|ubuntu +OS_ID="centos" + [install] -master1.kuggatest.k8s +master1.solarfs.k8s [masters] -master1.kuggatest.k8s ansible_host=172.16.195.211 +master1.solarfs.k8s ansible_host=172.16.195.211 [nodes] -infra1.kuggatest.k8s ansible_host=172.16.3.85 -node1.kuggatest.k8s ansible_host=172.16.128.250 -node2.kuggatest.k8s ansible_host=172.16.214.182 +infra1.solarfs.k8s ansible_host=172.16.3.85 +node1.solarfs.k8s ansible_host=172.16.128.250 +node2.solarfs.k8s ansible_host=172.16.214.182 [new_nodes] diff --git a/roles/host-init/tasks/apt.yml b/roles/host-init/tasks/apt.yml new file mode 100644 index 0000000..59fea84 --- /dev/null +++ b/roles/host-init/tasks/apt.yml @@ -0,0 +1,36 @@ +- name: clean repo cache + command: apt clean && apt update + ignore_errors: yes + tags: aptrepo + +- name: Install base tools + apt: + name: + - wget + - net-tools + - dnsutils + - bash-completion + - telnet + - curl + - lrzsz + - jq + - linux-tools-common + - strace + - vim + - iotop + - dnsmasq + - iproute2 + - nfs-common + - python3-selinux + - policycoreutils + - apt-transport-https + - ca-certificates + - gnupg + - lsb-release + tags: install-base-tools + +- name: Install kubernetes repo + shell: curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - && echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list + +- name: Install docker repo + shell: echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null diff --git a/roles/host-init/tasks/docker.yml b/roles/host-init/tasks/docker.yml index 7b2132e..023f684 100644 --- a/roles/host-init/tasks/docker.yml +++ b/roles/host-init/tasks/docker.yml @@ -1,10 +1,13 @@ +# centos uninstall docker - name: uninstall podman yum: name: - runc state: absent autoremove: true + when: OS_ID == "centos" +# centos install docker - name: Install docker ce yum: name: @@ -15,6 +18,32 @@ - docker-ce - docker-ce-cli tags: docker + when: OS_ID == "centos" + +# ubuntu uninstall docker +- name: uninstall docker + apt: + name: + - docker + - docker-engine + - docker.io + - containerd + - runc + state: absent + autoremove: true + when: OS_ID == "ubuntu" + +# ubuntu install docker +- name: Install docker ce + apt: + name: + - lvm2 + - containerd.io + - docker-ce + - docker-ce-cli + update_cache: yes + tags: docker + when: OS_ID == "ubuntu" - name: Create /etc/docker directory file: diff --git a/roles/host-init/tasks/installKubeadm.yml b/roles/host-init/tasks/installKubeadm.yml index a61b105..b1ae37e 100644 --- a/roles/host-init/tasks/installKubeadm.yml +++ b/roles/host-init/tasks/installKubeadm.yml @@ -6,6 +6,18 @@ - kubectl-{{k8s_version}} - bash-completion tags: kubeadm + when: OS_ID == "centos" + +- name: Install kubeadm kubelet kubectl + apt: + name: + - kubelet={{k8s_version}}-00 + - kubeadm={{k8s_version}}-00 + - kubectl={{k8s_version}}-00 + - bash-completion + update_cache: yes + tags: kubeadm + when: OS_ID == "ubuntu" - name: Kubectl completion bash shell: "kubectl completion bash >/etc/bash_completion.d/kubectl" @@ -15,6 +27,7 @@ template: src=kubelet.j2 dest=/etc/sysconfig/kubelet owner=root group=root mode=644 backup=yes notify: restart kubelet tags: kubeadm + when: OS_ID == "centos" - name: Enable service kubelet and start service: diff --git a/roles/host-init/tasks/ipvs.yml b/roles/host-init/tasks/ipvs.yml index cddb188..65e0385 100644 --- a/roles/host-init/tasks/ipvs.yml +++ b/roles/host-init/tasks/ipvs.yml @@ -7,6 +7,18 @@ - conntrack - libseccomp tags: ipvs + when: OS_ID == "centos" + +- name: Install ipvsadm + apt: + name: + - ipvsadm + - ipset + - sysstat + - conntrack + - libseccomp-dev + tags: ipvs + when: OS_ID == "ubuntu" - name: Modprode Kernel Module for IPVS modprobe: diff --git a/roles/host-init/tasks/main.yml b/roles/host-init/tasks/main.yml index ac13f55..f121cae 100644 --- a/roles/host-init/tasks/main.yml +++ b/roles/host-init/tasks/main.yml @@ -5,7 +5,11 @@ # CentOS # # ######## - include: yum.yml + when: OS_ID == "centos" +- include: apt.yml + when: OS_ID == "ubuntu" - include: selinux.yml + when: OS_ID == "centos" - include: ulimit.yml - include: ipvs.yml - include: sysctl.yml @@ -21,7 +25,9 @@ - include: apiServerDns.yml when: master_vip is defined - include: resolv.yml - when: public_network_node == False + when: public_network_node == False and OS_ID == "centos" +- include: resolvUbuntu.yml + when: public_network_node == False and OS_ID == "ubuntu" - include: publicInterface.yml when: public_network_node == True - include: reboot.yml diff --git a/roles/host-init/tasks/resolvUbuntu.yml b/roles/host-init/tasks/resolvUbuntu.yml new file mode 100644 index 0000000..92a449b --- /dev/null +++ b/roles/host-init/tasks/resolvUbuntu.yml @@ -0,0 +1,11 @@ +- name: delete resolv.conf + file: path=/etc/resolv.conf state=absent + tags: dns + +- name: config resolv.conf + template: src=resolv.conf.j2 dest=/etc/resolv.conf mode=0644 backup=yes + tags: dns + +- name: resolv.conf change immutable + file: path=/etc/resolv.conf attr=+i + tags: dns diff --git a/roles/host-init/tasks/update.yml b/roles/host-init/tasks/update.yml index 93f8bf9..5607564 100644 --- a/roles/host-init/tasks/update.yml +++ b/roles/host-init/tasks/update.yml @@ -1,3 +1,9 @@ - name: yum update command: yum update -y tags: yum-update + when: OS_ID == "centos" + +- name: apt upgrade + apt: + only_upgrade: yes + when: OS_ID == "ubuntu" From c74639baf89e715ccc10c6a20955d08244ab2db0 Mon Sep 17 00:00:00 2001 From: ss75710541 <75710541@qq.com> Date: Wed, 2 Mar 2022 19:08:18 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20add=20node=20=E6=94=AF=E6=8C=81ubun?= =?UTF-8?q?tu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roles/host-init/handlers/main.yml | 4 ++++ roles/host-init/tasks/apt.yml | 23 +++++++++++++++----- roles/host-init/tasks/main.yml | 2 -- roles/host-init/tasks/resolvUbuntu.yml | 11 ---------- roles/k8s-masters/templates/kube-dns.conf.j2 | 2 +- roles/k8s-nodes/templates/kube-dns.conf.j2 | 2 +- 6 files changed, 24 insertions(+), 20 deletions(-) delete mode 100644 roles/host-init/tasks/resolvUbuntu.yml diff --git a/roles/host-init/handlers/main.yml b/roles/host-init/handlers/main.yml index 6e80078..f3d1c56 100644 --- a/roles/host-init/handlers/main.yml +++ b/roles/host-init/handlers/main.yml @@ -19,3 +19,7 @@ - name: restart network service: name=network state=restarted become: yes + +- name: restart resolved + service: name=resolved state=restarted + become: yes diff --git a/roles/host-init/tasks/apt.yml b/roles/host-init/tasks/apt.yml index 59fea84..ee33812 100644 --- a/roles/host-init/tasks/apt.yml +++ b/roles/host-init/tasks/apt.yml @@ -3,6 +3,23 @@ ignore_errors: yes tags: aptrepo +- name: Add kubernetes repo key + apt_key: + url: https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg + state: present + +- name: Install kubernetes repo + shell: echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list + +- name: Add docker repo key + apt_key: + url: https://download.docker.com/linux/ubuntu/gpg + keyring: /usr/share/keyrings/docker-archive-keyring.gpg + state: present + +- name: Install docker repo + shell: echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + - name: Install base tools apt: name: @@ -27,10 +44,6 @@ - ca-certificates - gnupg - lsb-release + update_cache: yes tags: install-base-tools -- name: Install kubernetes repo - shell: curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - && echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list - -- name: Install docker repo - shell: echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null diff --git a/roles/host-init/tasks/main.yml b/roles/host-init/tasks/main.yml index f121cae..bd18b1e 100644 --- a/roles/host-init/tasks/main.yml +++ b/roles/host-init/tasks/main.yml @@ -26,8 +26,6 @@ when: master_vip is defined - include: resolv.yml when: public_network_node == False and OS_ID == "centos" -- include: resolvUbuntu.yml - when: public_network_node == False and OS_ID == "ubuntu" - include: publicInterface.yml when: public_network_node == True - include: reboot.yml diff --git a/roles/host-init/tasks/resolvUbuntu.yml b/roles/host-init/tasks/resolvUbuntu.yml deleted file mode 100644 index 92a449b..0000000 --- a/roles/host-init/tasks/resolvUbuntu.yml +++ /dev/null @@ -1,11 +0,0 @@ -- name: delete resolv.conf - file: path=/etc/resolv.conf state=absent - tags: dns - -- name: config resolv.conf - template: src=resolv.conf.j2 dest=/etc/resolv.conf mode=0644 backup=yes - tags: dns - -- name: resolv.conf change immutable - file: path=/etc/resolv.conf attr=+i - tags: dns diff --git a/roles/k8s-masters/templates/kube-dns.conf.j2 b/roles/k8s-masters/templates/kube-dns.conf.j2 index d913493..3efd0ca 100644 --- a/roles/k8s-masters/templates/kube-dns.conf.j2 +++ b/roles/k8s-masters/templates/kube-dns.conf.j2 @@ -8,5 +8,5 @@ cache-size=10000 bind-dynamic min-port=1024 interface={{LOCAL_ENNAME}} -except-interface=lo +#except-interface=lo # End of config diff --git a/roles/k8s-nodes/templates/kube-dns.conf.j2 b/roles/k8s-nodes/templates/kube-dns.conf.j2 index d913493..3efd0ca 100644 --- a/roles/k8s-nodes/templates/kube-dns.conf.j2 +++ b/roles/k8s-nodes/templates/kube-dns.conf.j2 @@ -8,5 +8,5 @@ cache-size=10000 bind-dynamic min-port=1024 interface={{LOCAL_ENNAME}} -except-interface=lo +#except-interface=lo # End of config From c596d643db84339b177ccb998bf5dcf4cffa6973 Mon Sep 17 00:00:00 2001 From: ss75710541 <75710541@qq.com> Date: Wed, 2 Mar 2022 19:10:45 +0800 Subject: [PATCH 3/3] update ansible.hosts.tpl --- ansible.hosts.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible.hosts.tpl b/ansible.hosts.tpl index 5fadc34..ed63909 100644 --- a/ansible.hosts.tpl +++ b/ansible.hosts.tpl @@ -62,6 +62,6 @@ master1.solarfs.k8s ansible_host=172.16.195.211 [nodes] infra1.solarfs.k8s ansible_host=172.16.3.85 node1.solarfs.k8s ansible_host=172.16.128.250 -node2.solarfs.k8s ansible_host=172.16.214.182 [new_nodes] +#node2.solarfs.k8s ansible_host=172.16.214.182 OS_ID="ubuntu"