mirror of
https://gitlab.sectorq.eu/jaydee/ansible.git
synced 2026-09-08 21:27:36 +02:00
build
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
- name: restart containerd
|
||||
systemd:
|
||||
name: containerd
|
||||
state: restarted
|
||||
enabled: yes
|
||||
@@ -0,0 +1,37 @@
|
||||
- name: Install kubernetes on Rocky 9
|
||||
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
|
||||
block:
|
||||
- name: Add NFS provisioner Helm repository
|
||||
kubernetes.core.helm_repository:
|
||||
name: nfs-subdir-external-provisioner
|
||||
repo_url: https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
|
||||
become: false
|
||||
when: inventory_hostname.endswith('-vm01.home.lan')
|
||||
|
||||
- name: List Helm repos
|
||||
ansible.builtin.command: helm repo list
|
||||
environment:
|
||||
HOME: /home/jd
|
||||
become: false
|
||||
register: helm_repos
|
||||
|
||||
- debug:
|
||||
var: helm_repos.stdout
|
||||
- name: Install NFS Subdir External Provisioner
|
||||
kubernetes.core.helm:
|
||||
name: nfs-storage
|
||||
chart_ref: nfs-subdir-external-provisioner/nfs-subdir-external-provisioner
|
||||
release_namespace: kube-system
|
||||
create_namespace: true
|
||||
update_repo_cache: true
|
||||
kubeconfig: /home/{{ ansible_user }}/.kube/config
|
||||
|
||||
values:
|
||||
nfs:
|
||||
server: "{{ nfs_server }}"
|
||||
path: /qda_1
|
||||
|
||||
storageClass:
|
||||
name: nfs-client
|
||||
defaultClass: true
|
||||
when: inventory_hostname.endswith('-vm01.home.lan')
|
||||
@@ -0,0 +1,262 @@
|
||||
- name: Install Kubernetes on Ubuntu 24
|
||||
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
|
||||
block:
|
||||
- name: Create apt proxy file
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/apt/apt.conf.d/02proxy
|
||||
content: |
|
||||
Acquire::http::Proxy "http://192.168.77.101:3142";
|
||||
Acquire::https::Proxy "false";
|
||||
|
||||
- name: Remove multiple files
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /etc/apt/sources.list.d/docker.list
|
||||
- /etc/apt/keyrings/docker.gpg
|
||||
- /etc/apt/trusted.gpg.d/containerd.gpg
|
||||
- /etc/apt/trusted.gpg.d/docker.gpg
|
||||
- name: Update apt cache
|
||||
apt:
|
||||
update_cache: yes
|
||||
|
||||
- name: Disable swap
|
||||
command: swapoff -a
|
||||
when: ansible_swaptotal_mb > 0
|
||||
|
||||
- name: Remove swap from fstab
|
||||
replace:
|
||||
path: /etc/fstab
|
||||
regexp: '.*swap.*'
|
||||
replace: ''
|
||||
|
||||
- name: Enable kernel modules
|
||||
copy:
|
||||
dest: /etc/modules-load.d/k8s.conf
|
||||
content: |
|
||||
overlay
|
||||
br_netfilter
|
||||
|
||||
- name: Load kernel modules
|
||||
modprobe:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
loop:
|
||||
- overlay
|
||||
- br_netfilter
|
||||
|
||||
- name: Set sysctl params
|
||||
copy:
|
||||
dest: /etc/sysctl.d/k8s.conf
|
||||
content: |
|
||||
net.bridge.bridge-nf-call-iptables = 1
|
||||
net.bridge.bridge-nf-call-ip6tables = 1
|
||||
net.ipv4.ip_forward = 1
|
||||
|
||||
- name: Apply sysctl
|
||||
command: sysctl --system
|
||||
|
||||
- name: Install required packages
|
||||
apt:
|
||||
name:
|
||||
- apt-transport-https
|
||||
- ca-certificates
|
||||
- curl
|
||||
- gpg
|
||||
- curl
|
||||
- gnupg2
|
||||
- software-properties-common
|
||||
state: present
|
||||
|
||||
- name: Remove old Docker repository files (if any)
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /etc/apt/sources.list.d/docker.list
|
||||
- /etc/apt/keyrings/docker.gpg
|
||||
- /etc/apt/trusted.gpg.d/containerd.gpg
|
||||
|
||||
- name: Create keyrings directory
|
||||
file:
|
||||
path: /etc/apt/keyrings
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Download Docker GPG key
|
||||
shell: |
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
|
||||
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||
|
||||
- name: Add Docker repository (Ubuntu 24 safe)
|
||||
apt_repository:
|
||||
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] \
|
||||
https://download.docker.com/linux/ubuntu noble stable"
|
||||
state: present
|
||||
filename: docker
|
||||
update_cache: no
|
||||
|
||||
- name: Update apt cache
|
||||
apt:
|
||||
update_cache: yes
|
||||
- name: Install required packages
|
||||
apt:
|
||||
name:
|
||||
- containerd.io
|
||||
state: present
|
||||
update_cache: yes
|
||||
|
||||
- name: Generate default containerd config
|
||||
command: containerd config default
|
||||
register: containerd_config
|
||||
|
||||
- name: Save containerd configuration
|
||||
copy:
|
||||
dest: /etc/containerd/config.toml
|
||||
content: "{{ containerd_config.stdout }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
- name: Enable SystemdCgroup in containerd config
|
||||
replace:
|
||||
path: /etc/containerd/config.toml
|
||||
regexp: 'SystemdCgroup\s*=\s*false'
|
||||
replace: 'SystemdCgroup = true'
|
||||
|
||||
- name: Restart containerd
|
||||
systemd:
|
||||
name: containerd
|
||||
state: restarted
|
||||
enabled: yes
|
||||
|
||||
- name: Add Kubernetes GPG key
|
||||
ansible.builtin.apt_key:
|
||||
url: https://pkgs.k8s.io/core:/stable:/v1.34/deb/Release.key
|
||||
keyring: /etc/apt/keyrings/k8s.gpg
|
||||
state: present
|
||||
|
||||
- name: Add Kubernetes repository
|
||||
copy:
|
||||
dest: /etc/apt/sources.list.d/k8s.list
|
||||
content: 'deb [signed-by=/etc/apt/keyrings/k8s.gpg] https://pkgs.k8s.io/core:/stable:/v1.34/deb/ /'
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
|
||||
- name: Install Kubernetes packages
|
||||
apt:
|
||||
name:
|
||||
- kubelet
|
||||
- kubeadm
|
||||
- kubectl
|
||||
state: present
|
||||
update_cache: yes
|
||||
|
||||
register: k8s_install
|
||||
retries: 5
|
||||
delay: 10
|
||||
until: k8s_install is succeeded
|
||||
|
||||
- name: Hold Kubernetes packages
|
||||
command: apt-mark hold kubelet kubeadm kubectl
|
||||
|
||||
- name: Enable kubelet
|
||||
systemd:
|
||||
name: kubelet
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
# Optional UFW configuration
|
||||
- name: Ensure UFW is installed
|
||||
apt:
|
||||
name: ufw
|
||||
state: present
|
||||
when: inventory_hostname == 'ubuntu24-vm01.home.lan'
|
||||
|
||||
- name: Allow Kubernetes ports
|
||||
ufw:
|
||||
rule: allow
|
||||
port: "{{ item }}"
|
||||
proto: tcp
|
||||
loop:
|
||||
- 6443
|
||||
- 2379:2380
|
||||
- 10250
|
||||
when: inventory_hostname == 'ubuntu24-vm01.home.lan'
|
||||
|
||||
- name: Configure containerd for kubeadm
|
||||
copy:
|
||||
dest: /etc/containerd/config.toml
|
||||
content: |
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd]
|
||||
snapshotter = "overlayfs"
|
||||
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
|
||||
runtime_type = "io.containerd.runc.v2"
|
||||
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
|
||||
SystemdCgroup = true
|
||||
|
||||
- name: Enable and start containerd
|
||||
systemd:
|
||||
name: containerd
|
||||
state: restarted
|
||||
|
||||
# - name: Pause for 5 minutes to build app cache
|
||||
# ansible.builtin.pause:
|
||||
# minutes: 2
|
||||
|
||||
- name: Create .kube directory
|
||||
file:
|
||||
path: /home/{{ ansible_user }}/.kube
|
||||
state: directory
|
||||
owner: "{{ ansible_user }}"
|
||||
group: "{{ ansible_user }}"
|
||||
mode: '0755'
|
||||
when: inventory_hostname == 'ubuntu24-vm01.home.lan'
|
||||
|
||||
- name: Initialize Kubernetes
|
||||
command: sudo kubeadm init --pod-network-cidr=10.244.0.0/16
|
||||
args:
|
||||
creates: /etc/kubernetes/admin.conf
|
||||
when: inventory_hostname == 'ubuntu24-vm01.home.lan'
|
||||
|
||||
|
||||
- name: Copy kubeconfig to user
|
||||
copy:
|
||||
remote_src: yes
|
||||
src: /etc/kubernetes/admin.conf
|
||||
dest: /home/{{ ansible_user }}/.kube/config
|
||||
owner: "{{ ansible_user }}"
|
||||
group: "{{ ansible_user }}"
|
||||
mode: '0644'
|
||||
when: inventory_hostname == 'ubuntu24-vm01.home.lan'
|
||||
# - name: Pause for 5 minutes to build app cache
|
||||
# ansible.builtin.pause:
|
||||
# minutes: 2
|
||||
|
||||
- name: Install Flannel CNI
|
||||
ansible.builtin.command:
|
||||
cmd: kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
|
||||
environment:
|
||||
KUBECONFIG: /etc/kubernetes/admin.conf
|
||||
when: inventory_hostname == "ubuntu24-vm01.home.lan"
|
||||
register: flannel_result
|
||||
changed_when: "'created' in flannel_result.stdout or 'configured' in flannel_result.stdout"
|
||||
|
||||
- name: Get join command
|
||||
command: sudo kubeadm token create --print-join-command
|
||||
register: join_command
|
||||
when: inventory_hostname == 'ubuntu24-vm01.home.lan'
|
||||
|
||||
- name: Save join command
|
||||
set_fact:
|
||||
worker_join_cmd: "{{ join_command.stdout }}"
|
||||
when: inventory_hostname == 'ubuntu24-vm01.home.lan'
|
||||
|
||||
- name: Join cluster
|
||||
command: "{{ hostvars['ubuntu24-vm01.home.lan'].worker_join_cmd }}"
|
||||
args:
|
||||
creates: /etc/kubernetes/kubelet.conf
|
||||
when: inventory_hostname != 'ubuntu24-vm01.home.lan'
|
||||
@@ -0,0 +1,10 @@
|
||||
- name: Include vault
|
||||
ansible.builtin.include_vars:
|
||||
file: jaydee.yml
|
||||
|
||||
- name: Facts
|
||||
ansible.builtin.setup:
|
||||
when: ansible_facts.architecture is not defined
|
||||
|
||||
- name: Include OS-specific tasks
|
||||
ansible.builtin.include_tasks: "{{ ansible_distribution }}.yml"
|
||||
@@ -0,0 +1,10 @@
|
||||
user_name: jd
|
||||
aliases:
|
||||
ll: "ls -la"
|
||||
gs: "git status"
|
||||
k: "kubectl"
|
||||
gk: "git clone git@gitlab.sectorq.eu:jaydee/kubernetes.git"
|
||||
|
||||
use_local_repo: true
|
||||
net_driver: calico
|
||||
nfs_server: 192.168.77.106
|
||||
Reference in New Issue
Block a user