Compare commits

..

No commits in common. "319c7b2a6f43b8d2e69e709d0fc26dfd1c807ef7" and "0997a2f86403d8b8f02941de060a7a582d5e4b44" have entirely different histories.

4 changed files with 11 additions and 52 deletions

View File

@ -8,4 +8,3 @@
[all:vars]
ansible_user=ansible
ansible_ssh_private_key_file=../terraform/.local/.ssh/id_rsa
ansible_python_interpreter=/usr/bin/python3

View File

@ -123,7 +123,9 @@
mode: "0755"
- name: Download Kubernetes GPG key securely
ansible.builtin.shell: curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
ansible.builtin.shell: |
set -o pipefail
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
- name: Add Kubernetes repository
ansible.builtin.apt_repository:
@ -137,7 +139,7 @@
- kubeadm
- kubectl
state: present
update_cache: yes
update_cache: true
- name: Hold kubelet, kubeadm, kubectl packages
ansible.builtin.command:
@ -211,8 +213,6 @@
- name: Initialize Kubernetes control plane
ansible.builtin.command:
cmd: kubeadm init --pod-network-cidr=10.244.0.0/16
creates: /tmp/kubeadm_output
register: kubeadm_init_output
become: true
changed_when: false
@ -223,17 +223,15 @@
owner: ansible
mode: "0755"
- name: Store Kubernetes initialization output to file
copy:
content: "{{ kubeadm_init_output.stdout }}"
dest: /tmp/kubeadm_output
become: true
delegate_to: localhost
- name: Generate join command
ansible.builtin.command: kubeadm token create --print-join-command
register: join_command
- name: Generate the Join Command
ansible.builtin.shell: cat /tmp/kubeadm_output | tail -n 2 | sed ':a;N;$!ba;s/\\\n\s*/ /g' > /tmp/join-command
- name: Copy join command to local file
ansible.builtin.copy:
content: '"{{ join_command.stdout_lines[0] }}"'
dest: '"/tmp/join-command"'
delegate_to: localhost
- name: Set permissions for the Join Executable
ansible.builtin.file:
path: /tmp/join-command

View File

@ -11,10 +11,6 @@
state: present
update_cache: true
- name: Set a hostname
ansible.builtin.hostname:
name: worker-{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}
- name: Install Docker
ansible.builtin.apt:
name: docker.io

View File

@ -10,10 +10,6 @@ terraform {
source = "hashicorp/template"
version = "2.2.0"
}
null = {
source = "hashicorp/null"
version = "3.2.3"
}
}
}
@ -51,9 +47,6 @@ resource libvirt_volume ubuntu2404_resized {
count = local.masternodes + local.workernodes
}
data template_file private_key {
template = file("${path.module}/.local/.ssh/id_rsa")
}
data template_file public_key {
template = file("${path.module}/.local/.ssh/id_rsa.pub")
@ -165,30 +158,3 @@ resource libvirt_domain k8s_workers {
autoport = true
}
}
resource null_resource run_ansible {
depends_on = [
libvirt_domain.k8s_masters,
libvirt_domain.k8s_workers
]
provisioner "local-exec" {
command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -vvv -i ../ansible/inventory.ini ../ansible/k8s.yml -K"
}
}
resource null_resource create_namespace {
depends_on = [
null_resource.run_ansible
]
provisioner "remote-exec" {
inline = ["sudo mkdir ~/.kube", "sudo cp /etc/kubernetes/admin.conf ~/.kube/", "sudo mv ~/.kube/admin.conf ~/.kube/config", "sudo service kubelet restart", "sudo kubectl --kubeconfig ~/.kube/config create namespace kiratech-test"]
connection {
host = libvirt_domain.k8s_masters[0].network_interface[0].addresses[0]
type = "ssh"
user = "ansible"
private_key = data.template_file.private_key.rendered
}
}
}