backup
This commit is contained in:
5
ksetup/end_tasks.yaml
Executable file
5
ksetup/end_tasks.yaml
Executable file
@ -0,0 +1,5 @@
|
||||
|
||||
#reboot
|
||||
- name: reboot
|
||||
reboot:
|
||||
|
1
ksetup/kubeadm-join.command
Normal file
1
ksetup/kubeadm-join.command
Normal file
@ -0,0 +1 @@
|
||||
kubeadm join 192.168.1.10:6443 --token ezekcz.n6hwck49wfvj4h6f --discovery-token-ca-cert-hash sha256:7f78629fddc1310a35d2534d5dafa77761fa9770ff4da871583e32bc549470f7
|
85
ksetup/master_tasks.yaml
Executable file
85
ksetup/master_tasks.yaml
Executable file
@ -0,0 +1,85 @@
|
||||
# Init
|
||||
- name: Init cluster
|
||||
ansible.builtin.command: "kubeadm init"
|
||||
become: true
|
||||
|
||||
# Set kubectl tool
|
||||
- user:
|
||||
name: "{{ ansible_user_id }}"
|
||||
state: present
|
||||
register: user_info_registered
|
||||
|
||||
- name: create .kube directory
|
||||
become: yes
|
||||
become_user: "{{ ansible_user_id }}"
|
||||
file:
|
||||
path: "{{ user_info_registered.home }}/.kube"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- debug: var=user_info_registered.home
|
||||
|
||||
- name: copy admin.conf to user's kube config
|
||||
copy:
|
||||
src: /etc/kubernetes/admin.conf
|
||||
remote_src: yes
|
||||
dest: "{{ user_info_registered.home }}/.kube/config"
|
||||
owner: "{{ ansible_user_id }}"
|
||||
become: true
|
||||
|
||||
|
||||
# Network Plugin
|
||||
|
||||
# Download and install Flannel
|
||||
|
||||
#- name: Download and install Flannel
|
||||
# ansible.builtin.get_url:
|
||||
# url: https://github.com/flannel-io/flannel/releases/download/v0.19.2/flanneld-arm64
|
||||
# dest: /usr/local/bin/flanneld
|
||||
# owner: root
|
||||
# group: root
|
||||
# mode: '0755'
|
||||
#
|
||||
#- name: Create Flannel networks directory
|
||||
# ansible.builtin.file:
|
||||
# path: /var/lib/k8s/flannel/networks
|
||||
# state: directory
|
||||
# recurse: yes
|
||||
# owner: root
|
||||
# group: root
|
||||
# mode: '0755'
|
||||
#-
|
||||
#
|
||||
- name: Calico
|
||||
ansible.builtin.command: "kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yaml"
|
||||
|
||||
#- name: Calico Tigera ?
|
||||
# ansible.builtin.shell: "kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/tigera-operator.yaml"
|
||||
# become_user: some_user
|
||||
#- name: Calico Custom resources ?
|
||||
# ansible.builtin.command: "kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/custom-resources.yaml"
|
||||
#
|
||||
#
|
||||
## Remove taints
|
||||
- name: Remove Taint (allows deployment in control plane)
|
||||
ansible.builtin.shell: "kubectl taint nodes --all node-role.kubernetes.io/control-plane-"
|
||||
|
||||
|
||||
# Join token / command
|
||||
|
||||
- name: Generate join token
|
||||
shell: kubeadm token create --print-join-command
|
||||
register: kubeadm_join_cmd
|
||||
|
||||
- set_fact:
|
||||
kubeadm_join_command: "{{ kubeadm_join_cmd.stdout }}"
|
||||
|
||||
- debug: var=kubeadm_join_command
|
||||
|
||||
- name: Store join command in "{{ kubeadm_join_path }}"
|
||||
copy:
|
||||
dest: "{{ kubeadm_join_path }}"
|
||||
content: |
|
||||
{{ kubeadm_join_command }}
|
||||
delegate_to: localhost
|
||||
|
47
ksetup/playbook.yaml
Executable file
47
ksetup/playbook.yaml
Executable file
@ -0,0 +1,47 @@
|
||||
# Author: Oriol Filter
|
||||
# 11/03/2023
|
||||
# Intended for armbian (bullseye, fuck ubuntu tho) it's aarch64
|
||||
# Maybe still works for orangepi "official" versions, but I don't care about them unless I used soooooo... gl!
|
||||
# https://medium.com/karlmax-berlin/how-to-install-kubernetes-on-raspberry-pi-53b4ce300b58
|
||||
- name: Preparethings
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
vars:
|
||||
|
||||
# Testing purpouses
|
||||
ansible_user: "orangepi" # Testing purposes
|
||||
ansible_password: "orangepi" # Testing purposes
|
||||
ansible_become_password: "orangepi" # Testing purposes
|
||||
|
||||
# Actual vars
|
||||
set_hostname: "{{ ansible_host }}"
|
||||
# is_master: Figurative
|
||||
|
||||
# Cluster shit
|
||||
kubeadm_join_path: "./kubeadm-join.command"
|
||||
kubeadm_join_command: ""
|
||||
|
||||
|
||||
tasks:
|
||||
# - check vars
|
||||
- debug: var=set_hostname
|
||||
- debug: var=is_master
|
||||
|
||||
# Init / Basic setup
|
||||
- name: set up node
|
||||
import_tasks: set_node_tasks.yaml
|
||||
become: true
|
||||
|
||||
# If is_master: init
|
||||
- name: init cluster
|
||||
import_tasks: master_tasks.yaml
|
||||
when: is_master
|
||||
|
||||
# else: join
|
||||
- name: join cluster
|
||||
import_tasks: slave_tasks.yaml
|
||||
when: not is_master
|
||||
|
||||
# Do other stuff
|
||||
- name: post setup
|
||||
import_tasks: end_tasks.yaml
|
201
ksetup/set_node_tasks.yaml
Executable file
201
ksetup/set_node_tasks.yaml
Executable file
@ -0,0 +1,201 @@
|
||||
# Hostname
|
||||
## Set hostname
|
||||
- name: Set a hostname
|
||||
ansible.builtin.hostname:
|
||||
name: "{{ set_hostname }}"
|
||||
|
||||
|
||||
# Swap
|
||||
- name: Swapoff
|
||||
ansible.builtin.command: swapoff -a
|
||||
|
||||
- name: Disable ram on boot (orangepi) # Untested
|
||||
copy:
|
||||
dest: "/etc/default/orangepi-zram-config"
|
||||
content: ENABLED=false
|
||||
when:
|
||||
- ansible_distribution | lower == "orangepi"
|
||||
- ansible_architecture == "aarch64"
|
||||
|
||||
- name: Disable ram on boot (armbian) # Untested
|
||||
copy:
|
||||
dest: "/etc/default/armbian-zram-config"
|
||||
content: ENABLED=false
|
||||
when:
|
||||
- ansible_architecture == "aarch64"
|
||||
- ansible_distribution | lower == "ubuntu" or ansible_distribution | lower == "debian"
|
||||
|
||||
|
||||
# INTENDED FOR ARM DISTROS FUCK U
|
||||
#- name: Sed when x86_64
|
||||
# ansible.builtin.command: sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
|
||||
# when: ansible_architecture == "x86_64"
|
||||
|
||||
|
||||
# Packages
|
||||
# Delete default containerd
|
||||
## Looking forward the version 1.6
|
||||
- name: apt prune containerd
|
||||
ansible.builtin.apt:
|
||||
name: containerd
|
||||
state: absent
|
||||
purge: true
|
||||
|
||||
## BnB
|
||||
- name: apt update
|
||||
ansible.builtin.apt:
|
||||
update_cache: yes
|
||||
|
||||
- name: apt upgrade
|
||||
ansible.builtin.apt:
|
||||
name: "*"
|
||||
state: latest
|
||||
|
||||
## Keyrings directory
|
||||
- name: Creating a new directory
|
||||
file:
|
||||
path: "/etc/apt/keyrings"
|
||||
state: directory
|
||||
recurse: true
|
||||
mode: '0755'
|
||||
# ignore_errors: true
|
||||
|
||||
## Docker repo
|
||||
- name: Add Docker GPG key
|
||||
apt_key:
|
||||
url: https://download.docker.com/linux/debian/gpg
|
||||
state: present
|
||||
|
||||
- name: Add Docker APT repository
|
||||
apt_repository:
|
||||
repo: deb [arch=arm64] https://download.docker.com/linux/debian bullseye stable
|
||||
state: present
|
||||
|
||||
## Kubeshit repo
|
||||
- name: Download Kubernetes GPG key
|
||||
ansible.builtin.get_url:
|
||||
url: "https://packages.cloud.google.com/apt/doc/apt-key.gpg"
|
||||
dest: "/etc/apt/keyrings/kubernetes-archive-keyring.gpg"
|
||||
timeout: 10
|
||||
|
||||
- name: Add Kubernetes keyring
|
||||
copy:
|
||||
dest: "/etc/apt/sources.list.d/kubernetes.list"
|
||||
content: "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main"
|
||||
|
||||
|
||||
## Install packages
|
||||
- name: apt update
|
||||
ansible.builtin.apt:
|
||||
update_cache: yes
|
||||
|
||||
- name: Install Kubelet Kubeadm Kubectl
|
||||
ansible.builtin.apt:
|
||||
pkg:
|
||||
- kubelet
|
||||
- kubeadm
|
||||
- kubectl
|
||||
|
||||
- name: Hold kubeadm
|
||||
ansible.builtin.dpkg_selections:
|
||||
name: kubeadm
|
||||
selection: hold
|
||||
|
||||
- name: Hold kubelet
|
||||
ansible.builtin.dpkg_selections:
|
||||
name: kubelet
|
||||
selection: hold
|
||||
|
||||
- name: Hold kubectl
|
||||
ansible.builtin.dpkg_selections:
|
||||
name: kubectl
|
||||
selection: hold
|
||||
|
||||
## Containerd
|
||||
- name: Install Container Runtime
|
||||
ansible.builtin.apt:
|
||||
pkg:
|
||||
- containerd.io
|
||||
- containernetworking-plugins
|
||||
|
||||
- name: Containerd set default config
|
||||
ansible.builtin.shell: containerd config default | tee /etc/containerd/config.toml
|
||||
become: yes
|
||||
|
||||
- name: SystemdCgroup = true
|
||||
lineinfile:
|
||||
dest: /etc/containerd/config.toml
|
||||
regexp: '^\s*SystemdCgroup = false$'
|
||||
line: ' SystemdCgroup = true'
|
||||
backrefs: yes
|
||||
|
||||
# Iptables
|
||||
## Set files
|
||||
- name: Iptables thingies (not touching specific firewall rules.)
|
||||
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: Iptables thingies
|
||||
copy:
|
||||
dest: "/etc/modules-load.d/k8s.conf"
|
||||
content: |
|
||||
overlay
|
||||
br_netfilter
|
||||
|
||||
## Modprobe
|
||||
- name: Add the overlay module
|
||||
community.general.modprobe:
|
||||
name: overlay
|
||||
state: present
|
||||
|
||||
- name: Add the br_netfilter module
|
||||
community.general.modprobe:
|
||||
name: br_netfilter
|
||||
state: present
|
||||
|
||||
- name: Apply changes (might need to use sysctl module with the reload flag, will try eventually)
|
||||
ansible.builtin.command: "sysctl --system"
|
||||
|
||||
|
||||
## Systemctl
|
||||
### Enable
|
||||
- name: Enable kubelet
|
||||
ansible.builtin.systemd:
|
||||
name: kubelet
|
||||
enabled: true
|
||||
|
||||
- name: Enable containerd
|
||||
ansible.builtin.systemd:
|
||||
name: containerd
|
||||
enabled: true
|
||||
|
||||
### Restart
|
||||
- name: Enable kubelet
|
||||
ansible.builtin.systemd:
|
||||
name: kubelet
|
||||
state: restarted
|
||||
|
||||
- name: Restart containerd
|
||||
ansible.builtin.systemd:
|
||||
name: containerd
|
||||
state: restarted
|
||||
|
||||
## Set /etc/hosts
|
||||
### This could be better but who cares
|
||||
- name: Set /etc/hosts file content (template/base)
|
||||
copy:
|
||||
dest: "/etc/hosts"
|
||||
content: |
|
||||
127.0.0.1 localhost
|
||||
127.0.1.1 {{ set_hostname }}
|
||||
::1 localhost {{ set_hostname }} ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
|
||||
|
8
ksetup/slave_tasks.yaml
Executable file
8
ksetup/slave_tasks.yaml
Executable file
@ -0,0 +1,8 @@
|
||||
- name: Populate {{ kubeadm_join_command }}
|
||||
ansible.builtin.set_fact: kubeadm_join_command="{{ lookup('file', kubeadm_join_path ) }}"
|
||||
|
||||
- debug: var=kubeadm_join_command
|
||||
|
||||
- name: Join kubeadm
|
||||
ansible.builtin.command: "{{ kubeadm_join_command }}"
|
||||
become: yes
|
Reference in New Issue
Block a user