🏗️」 wip: work in progress, not done yet.

This commit is contained in:
2025-08-12 20:55:11 +02:00
parent d7bc6cb929
commit a77f436878
8 changed files with 148 additions and 0 deletions

24
p1/Vagrantfile vendored
View File

@ -34,10 +34,34 @@ Vagrant.configure("2") do |config|
config.vm.define "#{IOT_LOGIN}S" do |server|
server.vm.hostname = "#{IOT_LOGIN}S"
server.vm.network "private_network", ip: "192.168.56.110", auto_config: true
server.vm.provision "ansible" do |ansible|
ansible.playbook = "playbooks.yml"
ansible.groups = {
"masters" => ["#{IOT_LOGIN}S"],
"workers" => ["#{IOT_LOGIN}SW"]
}
ansible.extra_vars = {
node_ip: "192.168.56.110",
node_name: "master",
pod_network: "192.168.56.64/26"
}
end
end
config.vm.define "#{IOT_LOGIN}SW" do |serverworker|
serverworker.vm.hostname = "#{IOT_LOGIN}SW"
serverworker.vm.network "private_network", ip: "192.168.56.111", auto_config: true
serverworker.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
ansible.groups = {
"masters" => ["#{IOT_LOGIN}S"],
"workers" => ["#{IOT_LOGIN}SW"]
}
ansible.extra_vars = {
node_ip: "192.168.56.111",
}
end
end
end

16
p1/playbooks.yml Normal file
View File

@ -0,0 +1,16 @@
---
- hosts: all
become: yes
roles:
- common
- hosts: masters
become: yes
roles:
- master
- hosts: workers
become: yes
roles:
- worker

View File

@ -0,0 +1,15 @@
gpg_keys:
- key: https://pkgs.k8s.io/core:/stable:/v1.33/deb/Release.key
repositories:
- repo: "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.33/deb/ /"
https_packages:
- name: apt-transport-https
- name: curl
- name: gpg
k8s_packages:
- name: kubeadm
- name: kubelet
- name: kubectl

View File

@ -0,0 +1,2 @@
---
dependencies: []

View File

@ -0,0 +1,60 @@
---
- name: Install packages that allow apt to be used over HTTPS
apt:
name='{{ item.name }}'
state=present
update_cache=yes
with_items: "{{ https_packages | default([]) }}"
- name: Ensure keyrings directory exists
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
- name: Download and install Kubernetes apt GPG key (dearmored)
shell: |
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.33/deb/Release.key | gpg --dearmor | tee /etc/apt/keyrings/kubernetes-apt-keyring.gpg > /dev/null
args:
creates: /etc/apt/keyrings/kubernetes-apt-keyring.gpg
- name: Add Kubernetes apt repository
apt_repository:
repo: "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.33/deb/ /"
filename: kubernetes
state: present
- name: Remove swapfile from /etc/fstab
mount:
name: "{{ item }}"
fstype: swap
state: absent
with_items:
- swap
- none
- name: Disable swap
command: swapoff -a
when: ansible_swaptotal_mb > 0
- name: Install Kubernetes binaries
apt:
name="{{ item.name }}"
state=present
update_cache=yes
with_items: "{{ k8s_packages | default([]) }}"
- name: Configure node ip
lineinfile:
path: '/etc/systemd/system/kubelet.service.d/10-kubeadm.conf'
line: 'Environment="KUBELET_EXTRA_ARGS=--node-ip={{ node_ip }}"'
regexp: 'KUBELET_EXTRA_ARGS='
insertafter: '\[Service\]'
state: present
notify:
- restart kubelet

View File

@ -0,0 +1,23 @@
---
- name: Initialize the Kubernetes cluster using kubeadm
command: kubeadm init --apiserver-advertise-address="{{ node_ip }}" --apiserver-cert-extra-sans="{{ node_ip }}" --node-name="{{ node_name }}" --pod-network-cidr={{ pod_network }}
- name: Setup kubeconfig for vagrant user
command: "{{ item }}"
with_items:
- mkdir -p /home/vagrant/.kube
- cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config
- chown vagrant:vagrant /home/vagrant/.kube/config
- name: Install flannel pod network
become: false
command: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
- name: Generate join command
command: kubeadm token create --print-join-command
register: join_command
- name: Copy join command to local file
become: false
local_action: copy content="{{ join_command.stdout_lines[0] }}" dest="./join-command"

View File

@ -0,0 +1,7 @@
---
- name: Copy the join command to server location
copy: src=join-command dest=/tmp/join-command.sh mode=0777
- name: Join the node to cluster
command: sh /tmp/join-command.sh

View File

@ -8,6 +8,7 @@ pkgs.mkShell {
vagrant
kubectl
just
ansible
# Virtual Machine
nixos-generators