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..ed63909 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 [new_nodes] +#node2.solarfs.k8s ansible_host=172.16.214.182 OS_ID="ubuntu" 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 new file mode 100644 index 0000000..ee33812 --- /dev/null +++ b/roles/host-init/tasks/apt.yml @@ -0,0 +1,49 @@ +- name: clean repo cache + command: apt clean && apt update + 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: + - 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 + update_cache: yes + tags: install-base-tools + 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..bd18b1e 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,7 @@ - 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: publicInterface.yml when: public_network_node == True - include: reboot.yml 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" 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