From 1d51266e6be7933723278b57e5390fe8b1a749d0 Mon Sep 17 00:00:00 2001 From: staffadmin Date: Sun, 1 Oct 2023 12:27:11 +0200 Subject: [PATCH] Bootstrap kubernetes cluster worker and master ok --- host_vars/ubuntu-worker.yml | 25 +++++++++++++++++++++++++ host_vars/vagrant.yml | 3 +++ hosts | 21 ++++++++++++++------- kube.yml | 30 ++++++++++++++++++++++++++---- 4 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 host_vars/ubuntu-worker.yml diff --git a/host_vars/ubuntu-worker.yml b/host_vars/ubuntu-worker.yml new file mode 100644 index 0000000..8b8f02f --- /dev/null +++ b/host_vars/ubuntu-worker.yml @@ -0,0 +1,25 @@ +--- +kubernetes_version: 1.28 +kubernetes_role: node + +kubernetes_alias_bashrc: + - path: "/root/.bashrc" + regexp: "^source /usr/share/bash-completion/bash_completion" + state: present + line: "source /usr/share/bash-completion/bash_completion" + - path: "/root/.bashrc" + regexp: "^source /etc/bash_completion" + state: present + line: "source /etc/bash_completion" + - path: "/root/.bashrc" + regexp: "^source <(kubectl completion bash)" + state: present + line: "source <(kubectl completion bash)" + - path: "/root/.bashrc" + regexp: "^alias k=kubectl" + state: present + line: "alias k=kubectl" + - path: "/root/.bashrc" + regexp: "^complete -F __start_kubectl k" + state: present + line: "complete -F __start_kubectl k" \ No newline at end of file diff --git a/host_vars/vagrant.yml b/host_vars/vagrant.yml index bc6a8fc..5ad95f4 100644 --- a/host_vars/vagrant.yml +++ b/host_vars/vagrant.yml @@ -57,6 +57,9 @@ kubernetes_git_repo: perso-infra kubernetes_git_url: github.com + +kubernetes_allow_pods_on_control_plane: false + kubernetes_alias_bashrc: - path: "/root/.bashrc" regexp: "^source /usr/share/bash-completion/bash_completion" diff --git a/hosts b/hosts index 013d25a..ed0f23f 100644 --- a/hosts +++ b/hosts @@ -1,10 +1,10 @@ -[perso] -ovh_fr ansible_host=37.187.127.90 ansible_user=stephane -scaleway_fr ansible_host=163.172.84.28 ansible_user=stephane +; [perso] +; ovh_fr ansible_host=37.187.127.90 ansible_user=stephane +; scaleway_fr ansible_host=163.172.84.28 ansible_user=stephane -# TO KNOW WHOIS CHISEL SERVER -[server] -scaleway_fr ansible_host=163.172.84.28 ansible_user=stephane +; # TO KNOW WHOIS CHISEL SERVER +; [server] +; scaleway_fr ansible_host=163.172.84.28 ansible_user=stephane ; [ovh] ; ovh_fr ansible_host=37.187.127.90 ansible_user=stephane @@ -13,4 +13,11 @@ scaleway_fr ansible_host=163.172.84.28 ansible_user=stephane ; scaleway_fr ansible_host=163.172.84.28 ansible_user=stephane [local] -vagrant ansible_host=192.168.33.10 ansible_user=vagrant ansible_password=vagrant \ No newline at end of file +vagrant ansible_host=192.168.33.10 ansible_user=vagrant ansible_password=vagrant +ubuntu-worker ansible_host=192.168.33.11 ansible_user=vagrant ansible_password=vagrant + +[workers] +ubuntu-worker ansible_host=192.168.33.11 ansible_user=vagrant ansible_password=vagrant + + +#kubectl label node ubuntu-worker node-role.kubernetes.io/worker ubuntu-worker \ No newline at end of file diff --git a/kube.yml b/kube.yml index 50ef72d..c90ec75 100644 --- a/kube.yml +++ b/kube.yml @@ -7,6 +7,8 @@ # # @author Stéphane Gratias (2023). # # +# Use hostname node and control_plane to join the kubernetes cluster + pre_tasks: - name: >- @@ -25,8 +27,16 @@ - overlay - br_netfilter tags: - - always + - kubernetes + - name: Set ipv4 forwarding on kubernetes node only + ansible.posix.sysctl: + name: net.ipv4.ip_forward + value: '1' + sysctl_set: true + when: kubernetes_role == 'node' + tags: + - kubernetes roles: - { role: geerlingguy.containerd, tags: [kubernetes, containerd] } @@ -34,6 +44,17 @@ tasks: +# labeled worker + - name: Labeled workers from master + command: "kubectl label node {{ item }} node-role.kubernetes.io/worker={{ item }}" + loop: "{{ groups['workers'] }}" + when: + - kubernetes_role == 'control_plane' + - groups['workers'] is defined + tags: + - kubernetes + - alias + - name: Add kubectl alias and completion ansible.builtin.lineinfile: path: "{{ item.path }}" @@ -55,10 +76,11 @@ with_items: - "{{ kubernetes_tree_base_dir | last }}" - "{{ kubernetes_tree_base_dir | last }}/{{ kubernetes_service }}" - tags: - - kubernetes + tags: - git +#kubectl label node node-role.kubernetes.io/=