Bootstrap kubernetes cluster worker and master ok

This commit is contained in:
2023-10-01 12:27:11 +02:00
parent 511dcde61a
commit 1d51266e6b
4 changed files with 68 additions and 11 deletions

View File

@@ -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"

View File

@@ -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"

21
hosts
View File

@@ -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
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

View File

@@ -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 name> node-role.kubernetes.io/<role name>=<key
# - name: Allow pods on control plane (if configured).
# command: "kubectl taint nodes --all node-role.kubernetes.io/control-plane-"
# when:
@@ -85,7 +107,7 @@
tags:
- test
- name: Apply metrics-server manifest to the cluster.
- name: Apply argocd manifest to the cluster.
kubernetes.core.k8s:
state: present
namespace: argocd