From 99ad1129b9dbb080e7e5f9394c8a81394c82cbd6 Mon Sep 17 00:00:00 2001 From: phil Date: Thu, 29 Dec 2022 15:23:42 +0100 Subject: [PATCH] reorg avec common --- k8s/kubernetes-setup/common.yml | 141 ++++++++++++++++++++++ k8s/kubernetes-setup/master-playbook.yml | 142 +---------------------- k8s/kubernetes-setup/node-playbook.yml | 134 +-------------------- 3 files changed, 143 insertions(+), 274 deletions(-) create mode 100644 k8s/kubernetes-setup/common.yml diff --git a/k8s/kubernetes-setup/common.yml b/k8s/kubernetes-setup/common.yml new file mode 100644 index 0000000..930222b --- /dev/null +++ b/k8s/kubernetes-setup/common.yml @@ -0,0 +1,141 @@ +--- + tasks: + - name: Set timezone to Europe/Paris + community.general.timezone: + name: Europe/Paris + + - name: maj fichier hosts + ansible.builtin.blockinfile: + path: /etc/hosts + block: | + 192.168.56.10 k8s-master + 192.168.56.11 node-1 + 192.168.56.12 node-2 + + - name: Forwarding IPv4 and letting iptables see bridged traffic + ansible.builtin.blockinfile: + path: /etc/modules-load.d/k8s.conf + create: yes + block: | + overlay + br_netfilter + + - name: charge module overlay + community.general.modprobe: + state: present + name: overlay + + - name: charge module overlay et br_netfilter + community.general.modprobe: + state: present + name: br_netfilter + + - name: persistance des bridges + ansible.builtin.blockinfile: + path: /etc/sysctl.d/k8s.conf + create: yes + block: | + net.bridge.bridge-nf-call-iptables = 1 + net.bridge.bridge-nf-call-ip6tables = 1 + net.ipv4.ip_forward = 1 + + - name: applique les parametres sysctl + command: "sysctl --system" + + - name: Recupere get-docker + get_url: + url: "https://get.docker.com" + dest: /tmp/get-docker.sh + + - name: lance get-docker - installe docker, containerd ... + command: 'sh /tmp/get-docker.sh' + + - name: Add vagrant user to docker group + user: + name: vagrant + group: docker + + - name: cree repertoire /etc/containerd + file: + path: /etc/containerd + state: directory + + - name: genere config.toml (containerd) + #command: "sudo containerd config default | sudo tee /etc/containerd/config.toml" + shell: "containerd config default | tee /etc/containerd/config.toml" + + - name: configure cgroup driver pour systemd (config.toml) + replace: + path: "/etc/containerd/config.toml" + regexp: 'SystemdCgroup = false' + replace: 'SystemdCgroup = true' + backup: yes + + - name: redemarre containerd + service: + name: containerd + state: restarted + enabled: yes + + - name: Remove swapfile from /etc/fstab + mount: + name: "{{ item }}" + fstype: swap + state: absent + with_items: + - swap + - none + + - name: Disable swap + command: swapoff -a + when: ansible_swaptotal_mb > 0 + + - name: Add an apt signing key for Kubernetes + apt_key: + url: https://packages.cloud.google.com/apt/doc/apt-key.gpg + state: present + + - name: Adding apt repository for Kubernetes + apt_repository: + repo: deb https://apt.kubernetes.io/ kubernetes-xenial main + state: present + filename: kubernetes.list + + - name: Install Kubernetes binaries + apt: + name: "{{ packages }}" + state: present + update_cache: yes + vars: + packages: + - kubelet + - kubeadm + - kubectl + + - name: Cree file kubelet + ansible.builtin.file: + path: /etc/default/kubelet + state: touch + + - name: Configure node ip + lineinfile: + path: /etc/default/kubelet + line: KUBELET_EXTRA_ARGS=--node-ip={{ node_ip }} + create: yes + + - name: Restart kubelet + service: + name: kubelet + daemon_reload: yes + state: restarted + + # - name: nettoie config.toml + # file: + # path: /etc/containerd/config.toml + # state: absent + + - name: redemarre containerd + service: + name: containerd + state: restarted + diff --git a/k8s/kubernetes-setup/master-playbook.yml b/k8s/kubernetes-setup/master-playbook.yml index d2af305..990c591 100644 --- a/k8s/kubernetes-setup/master-playbook.yml +++ b/k8s/kubernetes-setup/master-playbook.yml @@ -2,144 +2,7 @@ - hosts: all become: true tasks: - - name: Set timezone to Europe/Paris - community.general.timezone: - name: Europe/Paris - - - name: maj fichier hosts - ansible.builtin.blockinfile: - path: /etc/hosts - block: | - 192.168.56.10 k8s-master - 192.168.56.11 node-1 - 192.168.56.12 node-2 - - - name: Forwarding IPv4 and letting iptables see bridged traffic - ansible.builtin.blockinfile: - path: /etc/modules-load.d/k8s.conf - create: yes - block: | - overlay - br_netfilter - - - name: charge module overlay - community.general.modprobe: - state: present - name: overlay - - - name: charge module overlay et br_netfilter - community.general.modprobe: - state: present - name: br_netfilter - - - name: persistance des bridges - ansible.builtin.blockinfile: - path: /etc/sysctl.d/k8s.conf - create: yes - block: | - net.bridge.bridge-nf-call-iptables = 1 - net.bridge.bridge-nf-call-ip6tables = 1 - net.ipv4.ip_forward = 1 - - - name: applique les parametres sysctl - command: "sysctl --system" - - - name: Recupere get-docker - get_url: - url: "https://get.docker.com" - dest: /tmp/get-docker.sh - - - name: lance get-docker - installe docker, containerd ... - command: 'sh /tmp/get-docker.sh' - - - name: Add vagrant user to docker group - user: - name: vagrant - group: docker - - - name: cree repertoire /etc/containerd - file: - path: /etc/containerd - state: directory - - - name: genere config.toml (containerd) - #command: "sudo containerd config default | sudo tee /etc/containerd/config.toml" - shell: "containerd config default | tee /etc/containerd/config.toml" - - - name: configure cgroup driver pour systemd (config.toml) - replace: - path: "/etc/containerd/config.toml" - regexp: 'SystemdCgroup = false' - replace: 'SystemdCgroup = true' - backup: yes - - - name: redemarre containerd - service: - name: containerd - state: restarted - enabled: yes - - - name: Remove swapfile from /etc/fstab - mount: - name: "{{ item }}" - fstype: swap - state: absent - with_items: - - swap - - none - - - name: Disable swap - command: swapoff -a - when: ansible_swaptotal_mb > 0 - - - name: Add an apt signing key for Kubernetes - apt_key: - url: https://packages.cloud.google.com/apt/doc/apt-key.gpg - state: present - - - name: Adding apt repository for Kubernetes - apt_repository: - repo: deb https://apt.kubernetes.io/ kubernetes-xenial main - state: present - filename: kubernetes.list - - - name: Install Kubernetes binaries - apt: - name: "{{ packages }}" - state: present - update_cache: yes - vars: - packages: - - kubelet - - kubeadm - - kubectl - - - name: Cree file kubelet - ansible.builtin.file: - path: /etc/default/kubelet - state: touch - - - name: Configure node ip - lineinfile: - path: /etc/default/kubelet - line: KUBELET_EXTRA_ARGS=--node-ip={{ node_ip }} - create: yes - - - name: Restart kubelet - service: - name: kubelet - daemon_reload: yes - state: restarted - - # - name: nettoie config.toml - # file: - # path: /etc/containerd/config.toml - # state: absent - - - name: redemarre containerd - service: - name: containerd - state: restarted + - include_tasks: common.yml - name: Initialize the Kubernetes cluster using kubeadm command: kubeadm init --apiserver-advertise-address="{{ node_ip }}" --apiserver-cert-extra-sans="{{ node_ip }}" --node-name k8s-master --pod-network-cidr=192.168.0.0/16 @@ -153,9 +16,6 @@ - name: Install calico pod network become: false - #command: kubectl create -f https://docs.projectcalico.org/v3.24.5/getting-started/kubernetes/installation/hosted/calico.yaml -# command: kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.5/manifests/custom-resources.yaml -# command: "kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.5/manifests/tigera-operator.yaml" command: "kubectl create -f https://docs.projectcalico.org/manifests/calico-typha.yaml" - name: Generate join command diff --git a/k8s/kubernetes-setup/node-playbook.yml b/k8s/kubernetes-setup/node-playbook.yml index 23686e7..8b64eef 100644 --- a/k8s/kubernetes-setup/node-playbook.yml +++ b/k8s/kubernetes-setup/node-playbook.yml @@ -2,139 +2,7 @@ - hosts: all become: true tasks: - - name: Set timezone to Europe/Paris - community.general.timezone: - name: Europe/Paris - - - name: maj fichier hosts - ansible.builtin.blockinfile: - path: /etc/hosts - block: | - 192.168.56.10 k8s-master - 192.168.56.11 node-1 - 192.168.56.12 node-2 - - - name: Forwarding IPv4 and letting iptables see bridged traffic - ansible.builtin.blockinfile: - path: /etc/modules-load.d/k8s.conf - create: yes - block: | - overlay - br_netfilter - - - name: charge module overlay - community.general.modprobe: - state: present - name: overlay - - - name: charge module overlay et br_netfilter - community.general.modprobe: - state: present - name: br_netfilter - - - name: persistance des bridges - ansible.builtin.blockinfile: - path: /etc/sysctl.d/k8s.conf - create: yes - block: | - net.bridge.bridge-nf-call-iptables = 1 - net.bridge.bridge-nf-call-ip6tables = 1 - net.ipv4.ip_forward = 1 - - - name: applique les parametres sysctl - command: "sysctl --system" - - - name: Recupere get-docker - get_url: - url: "https://get.docker.com" - dest: /tmp/get-docker.sh - - - name: lance get-docker - installe docker, containerd ... - command: 'sh /tmp/get-docker.sh' - - - name: Add vagrant user to docker group - user: - name: vagrant - group: docker - - - name: cree repertoire /etc/containerd - file: - path: /etc/containerd - state: directory - - - name: genere config.toml (containerd) - #command: "sudo containerd config default | sudo tee /etc/containerd/config.toml" - shell: "containerd config default | tee /etc/containerd/config.toml" - - - name: configure cgroup driver pour systemd (config.toml) - replace: - path: "/etc/containerd/config.toml" - regexp: 'SystemdCgroup = false' - replace: 'SystemdCgroup = true' - backup: yes - - - name: redemarre containerd - service: - name: containerd - state: restarted - enabled: yes - - - name: Remove swapfile from /etc/fstab - mount: - name: "{{ item }}" - fstype: swap - state: absent - with_items: - - swap - - none - - - name: Disable swap - command: swapoff -a - when: ansible_swaptotal_mb > 0 - - - name: Add an apt signing key for Kubernetes - apt_key: - url: https://packages.cloud.google.com/apt/doc/apt-key.gpg - state: present - - - name: Adding apt repository for Kubernetes - apt_repository: - repo: deb https://apt.kubernetes.io/ kubernetes-xenial main - state: present - filename: kubernetes.list - - - name: Install Kubernetes binaries - apt: - name: "{{ packages }}" - state: present - update_cache: yes - vars: - packages: - - kubelet - - kubeadm - - kubectl - - - name: Cree file kubelet - ansible.builtin.file: - path: /etc/default/kubelet - state: touch - - - name: Configure node ip - lineinfile: - path: /etc/default/kubelet - line: KUBELET_EXTRA_ARGS=--node-ip={{ node_ip }} - create: yes - - - name: Restart kubelet - service: - name: kubelet - daemon_reload: yes - state: restarted - - - name: redemarre containerd - service: - name: containerd - state: restarted + - include_tasks: common.yml - name: Copy the join command to server location copy: