Compare commits

...

20 Commits

Author SHA1 Message Date
oriol
0648f1112c Fix for ubuntu server 2025-08-03 00:11:53 +02:00
oriol
567bd34c66 QoL and minor fixes 2025-06-04 01:24:29 +02:00
savagebidoof
380e011ca9 Increased to 40 seconds since im now using a node that uses wifi so it can take a bit longer ... 2024-03-10 22:00:09 +01:00
savagebidoof
d42567a399 Quemu restart was not useful and results in error.
To start Quemu, after installing, it requires Proxmox to enable Quemu on that specific VM, then shut down and power up again, a `reboot` won't surface.
2024-03-07 05:44:03 +01:00
savagebidoof
2f6ec13ee6 Slightly updated the README.md 2024-03-07 05:21:50 +01:00
savagebidoof
169e8a8913 Fixed issues with variables (looping), so renamed them to _var 2024-03-07 05:19:58 +01:00
savagebidoof
faa63611f0 fixed typo and improved quality. 2024-03-07 05:15:12 +01:00
savagebidoof
a704da7471 Typo 2024-03-07 04:46:39 +01:00
savagebidoof
253345f99f shouldn't be commented 2024-03-07 04:35:54 +01:00
savagebidoof
0c16a178e5 Added "is_proxmox_vm" and "setup_only" to prevent joining/creating a kubernetes cluster 2024-03-07 04:35:41 +01:00
savagebidoof
d62eaa0014 Increased kubernetes version to 1.29 2024-03-07 04:21:34 +01:00
savagebidoof
e8d529ac61 Updated manifests version, in the future will be moved to helm. 2024-03-07 04:20:45 +01:00
savagebidoof
54147126fb Playbook wasn't using then user variable to format the command. 2024-01-17 10:41:29 +01:00
savagebidoof
a9b93c6407 Replaces asc key for gpg. (kubernetes repo related.) 2024-01-14 00:17:49 +01:00
savagebidoof
e47d5d6498 Added installing step to install sudo. 2024-01-14 00:17:04 +01:00
savagebidoof
b0ace19010 Updated Kubernetes repo to math version .28, instead of targeting the old one. 2024-01-13 02:26:08 +01:00
savagebidoof
359b9405e9 Just removed 2 spaces, literally who cares. 2023-12-14 18:08:32 +01:00
savagebidoof
3f378c1d8e Insignificant changes.
Added install for `nfs-common` package, required for NFS mounting.
2023-12-14 02:45:28 +01:00
savagebidoof
1103475ea7 Forgot this uncommented. 2023-12-13 18:03:45 +01:00
savagebidoof
1986a71118 Added support for x64 bit Debian. 2023-12-13 17:14:13 +01:00
9 changed files with 221 additions and 117 deletions

View File

@@ -14,38 +14,107 @@
# New values
## Users
new_user_name: "kluser"
new_user_pass: "kluser_1234"
new_root_pass: "root_1234"
new_user_name: "my_user"
new_user_password: "my_password"
new_root_password: "my_root_password"
## Locales
new_locale: "en_US.UTF-8"
new_language: "en_US.UTF-8"
new_timezone: "Europe/Madrid"
# SSH with ROOT
tasks:
# Install sudo and locale thingies
- name: ping
ping:
# Install locale thingies and configure sudo for the new user
- name: apt update
ansible.builtin.apt:
update_cache: yes
#
- name: apt upgrade
ansible.builtin.apt:
name: "*"
state: latest
- name: Install sudo
#
- name: Install locale thingies and sudo
ansible.builtin.apt:
pkg:
- sudo
- locales
- locales-all
#
# - name: update facts
# setup:
#
# # Wheel group with sudo access
# # https://stackoverflow.com/a/33362805
- name: Make sure we have a 'wheel' group
group:
name: wheel
state: present
- name: update facts
setup:
# Set locale
- name: Allow 'wheel' group to have passwordless sudo
ansible.builtin.lineinfile:
dest: /etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) PASSWD: ALL'
validate: visudo -cf %s
# # Create `orangepi` (or whatever user u want to create) user (will bother about it later) # maybe move to -> kuser (kluster user)?
- name: Add user new_user_name
ansible.builtin.user:
name: "{{ new_user_name }}"
password: "{{ new_user_password | password_hash }}"
shell: /bin/bash
#
#
- name: adding user '{{ new_user_name }}' to group wheel
ansible.builtin.user:
name: '{{ new_user_name }}'
groups: sudo
append: yes
- name: Select new user
set_fact:
ansible_user: "{{ new_user_name }}"
ansible_password: "{{ new_user_password }}"
# Set root password to whatever shit
- name: Change root default password
ansible.builtin.user:
name: root
password: "{{ new_root_password | password_hash }}"
# Disable SSH with ROOT
- name: PermitRootLogin = no
ansible.builtin.lineinfile:
dest: /etc/ssh/sshd_config
regexp: '^PermitRootLogin'
line: PermitRootLogin no
backrefs: yes
# Disable SSH with empty password users
- name: PermitEmptyPasswords = no
ansible.builtin.lineinfile:
dest: /etc/ssh/sshd_config
regexp: '^PermitEmptyPasswords'
line: PermitEmptyPasswords = no
backrefs: yes
# Set locale
# https://serverfault.com/a/981742
# https://andreas.scherbaum.la/blog/archives/941-Configuring-locales-in-Debian-and-Ubuntu,-using-Ansible-Reloaded.html
- name: Ensure localisation files for '{{ new_locale }}' are available
@@ -76,70 +145,12 @@
# changed_when: locale_lang != new_locale or locale_language != new_language
# become: yes # no idea if it's needed, nor I care about
- name: Set timezone
command: timedatectl set-timezone {{ new_timezone }}
# Wheel group with sudo access
# https://stackoverflow.com/a/33362805
- name: Make sure we have a 'wheel' group
group:
name: wheel
state: present
# become: true
- name: Allow 'wheel' group to have passwordless sudo
ansible.builtin.lineinfile:
dest: /etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) PASSWD: ALL'
validate: visudo -cf %s
# become: true
# Create `orangepi` (or whatever user u want to create) user (will bother about it later) # maybe move to -> kuser (kluster user)?
- name: Add user new_user_name
ansible.builtin.user:
name: "{{ new_user_name }}"
password: "{{ new_user_pass | password_hash }}"
shell: /bin/bash
# become: true
- name: adding user '{{ new_user_name }}' to group wheel
ansible.builtin.user:
name: '{{ new_user_name }}'
groups: sudo
append: yes
# become: true
# Set root password to whatever shit
- name: Change root default password
ansible.builtin.user:
name: root
password: "{{ new_root_pass | password_hash }}"
# become: yes
# Disable SSH with ROOT
- name: PermitRootLogin = no
ansible.builtin.lineinfile:
dest: /etc/ssh/sshd_config
regexp: '^PermitRootLogin'
line: PermitRootLogin = no
backrefs: yes
# Disable SSH with empty password users
- name: PermitEmptyPasswords = no
ansible.builtin.lineinfile:
dest: /etc/ssh/sshd_config
regexp: '^PermitEmptyPasswords'
line: PermitEmptyPasswords = no
backrefs: yes
# become: yes
# REBOOT
# REBOOT
- name: reboot
# ansible.builtin.reboot:
ansible.builtin.shell: 'sleep 1 && dhclient -r && dhclient && reboot'
ansible.builtin.reboot:
ignore_unreachable: true
# become: yes
# become: no
# ansible.builtin.shell: 'sleep 1 && dhclient -r && dhclient && reboot'

View File

@@ -3,9 +3,16 @@
- Previously on the [orangepi](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/service-and-support/Orange-pi-5.html)
# Files
# Requirements
- Create a username named "orangepi" with password "orangepi".
- Install `sudo`.
- Allow the user "orangepi" to have access to sudo.
- The user "orangepi" will be later deleted, so it's fine.
# Files
```yaml
arm_initial_setup.yaml: standalone playbook to normalize the initialization of an ARMBIAN device
@@ -91,7 +98,9 @@ ansible_become_password: Password used to execute `sudo`
# Actual vars
set_hostname: New hostname for the device, by default will obtain it's values from the variable `ansible_host` aka. the URL specified to connect to such device.
is_master: This variable determines which playbooks will run.
is_master: This variable determines which playbooks will run. (default false)
is_proxmox_vm: If true it will install the quemu agent for monitoring. (default false)
setup_only: If true will prevent creating/joining a kubernetes cluster.
# Cluster shit
kubeadm_join_path: File path that will store the `kubeadm join` command to be executed by the worker nodes.
@@ -106,7 +115,8 @@ _kubeadm_join_command: Placeholder, will be populated at later stages of the scr
- Update -> Upgrade.
- Uninstalls `containerd`.
- Installs Docker (Debian) and Kubernetes repos.
- Installs `containerd.io`, `kubelet`, `kubeadm`, `kubectl`, `git`, `vim`.
- Installs `containerd.io`, `kubelet`, `kubeadm`, `kubectl`, `git`, `vim`. (and others)
- If the variable `is_proxmox_vm` is set to true, will also install the quemu agent.
- Sets default config for `containerd` with cGroups enabled.
- Enables some `iptables` modules.
- "Resets" `/etc/hosts` file
@@ -130,10 +140,14 @@ _kubeadm_join_command: Placeholder, will be populated at later stages of the scr
#### tasks_end.yaml
- As per the moment, only reboots.
- As per the moment, deletes the "default user specified" (usually orangepi, on my scenario atleast) then reboots the system.
# USAGE
## Update Calico/MetalLB versions
Open the file `tasks_master.yaml` and update the .yaml files for Calico and MetalLB to match the desired/newer versions.
## Setup
On my infrastructure/environment, **I** use a DHCP and DNS to connect / communicate the nodes.
@@ -191,7 +205,6 @@ ansible_password: "1234"
# License
## DWTFUW

View File

@@ -1,17 +1,22 @@
masters:
hosts:
pi4.filter.home:
vars:
is_master: yes
initial_username: root
initial_password: ""
delete_user_name: orangepi
#masters:
# hosts:
# pi4.filter.home:
# vars:
# is_master: yes
# initial_username: root
# initial_password: ""
# delete_user_name: orangepi
slaves:
hosts:
slave[02:02].filter.home:
slave[04:04].filter.home:
vars:
is_master: no
is_proxmox_vm: true
# setup_only: false
initial_username: orangepi
initial_password: orangepi
delete_user_name: orangepi
all:
vars:
kubernetes_version: 1.32

View File

@@ -1,5 +1,5 @@
# Author: Oriol Filter
# 30/07/2023
# 13/12/2023
# Intended for armbian (bullseye, fuck ubuntu tho) it's aarch64
# Maybe still works for orangepi "official" versions, but I only care of make it work for myself soooooo... gl!
# https://medium.com/karlmax-berlin/how-to-install-kubernetes-on-raspberry-pi-53b4ce300b58
@@ -10,10 +10,13 @@
vars:
# Testing purposes
ansible_user: "kluser" # Testing purposes
ansible_password: "kluser_1234" # Testing purposes
ansible_user: "adminuser" # Testing purposes
ansible_password: "adminpassword" # Testing purposes
ansible_become_password: "{{ ansible_password }}" # Testing purposes
# Kubernetes version
target_kubernetes_version: "{{ kubernetes_version }}" # Testing purposes
# Actual vars
set_hostname: "{{ ansible_host }}"
# is_master: Figurative
@@ -22,26 +25,37 @@
kubeadm_join_path: "./Exported/kubeadm-join.command"
_kubeadm_join_command: "" # Placeholder
# Others
_is_master: "{{ is_master | default('false') | bool }}" # Prevent creating/joining a cluster
_is_proxmox_vm: "{{ is_proxmox_vm | default('false') | bool }}" # Prevent creating/joining a cluster
_setup_only: "{{ setup_only | default('false') | bool }}" # Prevent creating/joining a cluster
tasks:
# - check vars
# check vars
- debug: var=set_hostname
- debug: var=is_master
- debug: var=_is_master
- debug: var=_is_proxmox_vm
- debug: var=_setup_only
- debug: var=target_kubernetes_version
- name: Ping check
ping:
# Init / Basic setup
- name: set up node
import_tasks: tasks_prepare_node.yaml
become: true
# If is_master: init
# If _is_master: init
- name: init cluster
import_tasks: tasks_master.yaml
when: is_master
when: _is_master and not _setup_only
become: true
# else: join
- name: join cluster
import_tasks: tasks_slave.yaml
when: not is_master
when: not _is_master and not _setup_only
# Do other stuff
- name: post setup

View File

@@ -1,10 +1,37 @@
# https://stackoverflow.com/questions/46515704/how-to-kill-a-running-process-using-ansible
- name: Get running processes
shell: "ps -ef | grep -v grep | grep -w ^{{ delete_user_name }} | awk '{print $2}'"
register: running_processes
when: delete_user_name is defined and delete_user_name | length > 0
- name: Debug Running processes
debug: var=running_processes
- name: Kill running processes
shell: "kill {{ item }}"
with_items: "{{ running_processes.stdout_lines }}"
when: (delete_user_name is defined) and (delete_user_name | length > 0) and (running_processes | length > 0)
- wait_for:
path: "/proc/{{ item }}/status"
state: absent
with_items: "{{ running_processes.stdout_lines }}"
ignore_errors: yes
register: killed_processes
when: (delete_user_name is defined) and (delete_user_name | length > 0) and (running_processes | length > 0)
- name: Force kill stuck processes
shell: "kill -9 {{ item }}"
with_items: "{{ killed_processes.results | select('failed') | map(attribute='item') | list }}"
when: (delete_user_name is defined) and (delete_user_name | length > 0) and (running_processes | length > 0)
- name: Delete user
ansible.builtin.user:
name: "{{ delete_user_name }}"
remove: true
state: absent
when: delete_user_name != ""
when: delete_user_name is defined and delete_user_name | length > 0
#reboot
- name: reboot

View File

@@ -22,12 +22,12 @@
### Calico
- name: Calico
ansible.builtin.command: "kubectl create --kubeconfig /etc/kubernetes/admin.conf -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/calico.yaml"
ansible.builtin.command: "kubectl create --kubeconfig /etc/kubernetes/admin.conf -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.2/manifests/calico.yaml"
## Extras
### MetalLB
- name: MetalLB
ansible.builtin.command: "kubectl create --kubeconfig /etc/kubernetes/admin.conf -f https://raw.githubusercontent.com/metallb/metallb/v0.13.10/config/manifests/metallb-native.yaml"
ansible.builtin.command: "kubectl create --kubeconfig /etc/kubernetes/admin.conf -f https://raw.githubusercontent.com/metallb/metallb/v0.14.3/config/manifests/metallb-native.yaml"
## Export join command

View File

@@ -4,7 +4,6 @@
ansible.builtin.hostname:
name: "{{ set_hostname }}"
# Swap
- name: Swapoff
ansible.builtin.command: swapoff -a
@@ -25,21 +24,32 @@
- ansible_architecture == "aarch64"
- ansible_distribution | lower == "ubuntu" or ansible_distribution | lower == "debian"
- name: Sed when x86_64
ansible.builtin.command: sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
when:
- ansible_architecture == "x86_64"
- 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"
- name: Sed when x86_64 (needed for ubuntu server atleast)
ansible.builtin.command: sed -i 's/^\/swap.img.*/##&/' /etc/fstab
when:
- ansible_architecture == "x86_64"
- ansible_distribution | lower == "ubuntu" or ansible_distribution | lower == "debian"
# Packages
# Delete default containerd
## Looking forward the version 1.6
- name: apt prune containerd
## Delete default containerd and kuberelated thingies
- name: apt prune containerd and other kube related
ansible.builtin.apt:
name: containerd
name:
- containerd
- kubelet
- kubeadm
- kubectl
state: absent
purge: true
allow_change_held_packages: true
## BnB
- name: apt update
@@ -65,27 +75,36 @@
mode: '0755'
# ignore_errors: true
## Docker repo
## Docker repo ARM/x64
- name: Add Docker GPG key
apt_key:
url: https://download.docker.com/linux/debian/gpg
state: present
- name: Add Docker APT repository
- name: Add Docker APT repository (ARM Arch)
apt_repository:
repo: deb [arch=arm64] https://download.docker.com/linux/debian bullseye stable
state: present
when:
- ansible_architecture == "aarch64"
## Kubeshit repo
- name: Add Docker APT repository (x64 Arch)
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/debian bullseye stable
state: present
when:
- ansible_architecture == "x86_64"
# Kubeshit repo
- name: Add Kubernetes GPG key
apt_key:
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
url: "https://pkgs.k8s.io/core:/stable:/v{{ target_kubernetes_version }}/deb/Release.key"
state: present
keyring: "/etc/apt/keyrings/kubernetes-apt-keyring-{{ target_kubernetes_version }}.gpg"
- name: Add Kubernetes APT repository
apt_repository:
repo: deb https://apt.kubernetes.io/ kubernetes-xenial main
repo: "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring-{{ target_kubernetes_version }}.gpg] https://pkgs.k8s.io/core:/stable:/v{{ target_kubernetes_version }}/deb/ /"
state: present
@@ -100,6 +119,7 @@
- kubelet
- kubeadm
- kubectl
- nfs-common # Required for NFS mounts
- git # fuck it, you will need it, maybe
- vim # fuck it, I need it.
@@ -180,7 +200,7 @@
name: containerd
enabled: true
### Restart
### Restart containerd
- name: Enable kubelet
ansible.builtin.systemd:
name: kubelet
@@ -206,3 +226,16 @@
ff02::2 ip6-allrouters
## ProxmoxVM related
- name: Install quemu-guest-agent
ansible.builtin.apt:
pkg:
- qemu-guest-agent
when: is_proxmox_vm
- name: Enable quemu-guest-agent
ansible.builtin.systemd:
name: qemu-guest-agent
enabled: true
# Quemu requires to be enabled on the Proxmox VM, after installing also requires to be shut down, and started again from the Proxmox GUI

View File

@@ -3,6 +3,6 @@
- debug: var=_kubeadm_join_command
- name: Join kubeadm
- name: Join kubeadm (this can take a while ... like 20 mins?? idk. probably lot less)
ansible.builtin.command: "{{ _kubeadm_join_command }}"
become: yes

3
run.sh
View File

@@ -1,7 +1,8 @@
#!/bin/bash
export ANSIBLE_HOST_KEY_CHECKING=False
#ansible-playbook -i inventory.yaml Initial_Setup/armbian_initial_setup.yaml && sleep 25 # Wait for reboot
ansible-playbook -i inventory.yaml Initial_Setup/armbian_initial_setup.yaml && printf "Giving some time (40s) to catch up to the reboot command ...\n" &&
sleep 40 && # Wait for reboot
ansible-playbook -i inventory.yaml ksetup/playbook.yaml