reorg avec common
This commit is contained in:
parent
6c16426120
commit
99ad1129b9
141
k8s/kubernetes-setup/common.yml
Normal file
141
k8s/kubernetes-setup/common.yml
Normal file
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user