add module to create a k8s worker [ci skip]
This commit is contained in:
parent
e0d8f7df3b
commit
1968f353a2
4 changed files with 59 additions and 8 deletions
16
main.tf
16
main.tf
|
|
@ -5,6 +5,7 @@ variable "prod" {
|
||||||
variable "proxmox_pm_api_url" { type = string }
|
variable "proxmox_pm_api_url" { type = string }
|
||||||
variable "proxmox_pm_api_token_id" { type = string }
|
variable "proxmox_pm_api_token_id" { type = string }
|
||||||
variable "proxmox_pm_api_token_secret" { type = string }
|
variable "proxmox_pm_api_token_secret" { type = string }
|
||||||
|
variable "k8s_join_command" { type = string }
|
||||||
variable "vm_wizard_password" { type = string }
|
variable "vm_wizard_password" { type = string }
|
||||||
variable "proxmox_host" { type = string }
|
variable "proxmox_host" { type = string }
|
||||||
variable "tls_secret_name" {}
|
variable "tls_secret_name" {}
|
||||||
|
|
@ -170,18 +171,21 @@ module "template-vm" {
|
||||||
template_id = 8000
|
template_id = 8000
|
||||||
template_name = local.vm_template_name
|
template_name = local.vm_template_name
|
||||||
|
|
||||||
snippet_name = local.vm_cloud_init_snippet_name
|
snippet_name = local.vm_cloud_init_snippet_name
|
||||||
user_passwd = var.vm_wizard_password
|
user_passwd = var.vm_wizard_password
|
||||||
|
k8s_join_command = var.k8s_join_command
|
||||||
}
|
}
|
||||||
|
|
||||||
# module "pxe-server" {
|
# module "k8s_node5" {
|
||||||
# template_name = local.vm_template_name
|
# template_name = local.vm_template_name
|
||||||
# source = "./modules/create-vm"
|
# source = "./modules/create-vm"
|
||||||
# vm_name = "pxe-server"
|
# vm_name = "k8s-node5"
|
||||||
# vm_disk_size = 50
|
# vmid = 205
|
||||||
# cisnippet_name = local.vm_cloud_init_snippet_name
|
# cisnippet_name = local.vm_cloud_init_snippet_name
|
||||||
# bridge = "vmbr0"
|
|
||||||
# vm_mac_address = "00:50:56:87:4a:2d"
|
# vm_mac_address = "00:50:56:87:4a:2d"
|
||||||
|
# bridge = "vmbr1"
|
||||||
|
# vlan_tag = "20"
|
||||||
# }
|
# }
|
||||||
|
|
||||||
# module "k8s_master" {
|
# module "k8s_master" {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ users:
|
||||||
- ${authorized_ssh_key}
|
- ${authorized_ssh_key}
|
||||||
passwd: ${passwd}
|
passwd: ${passwd}
|
||||||
lock_passwd: false # enable passwd login
|
lock_passwd: false # enable passwd login
|
||||||
|
shell: /bin/bash
|
||||||
package_update: true
|
package_update: true
|
||||||
package_upgrade: true
|
package_upgrade: true
|
||||||
packages:
|
packages:
|
||||||
|
|
@ -20,3 +21,35 @@ packages:
|
||||||
- wget
|
- wget
|
||||||
- net-tools
|
- net-tools
|
||||||
- zsh
|
- zsh
|
||||||
|
- apt-transport-https
|
||||||
|
- ca-certificates
|
||||||
|
- gpg
|
||||||
|
# docker
|
||||||
|
- docker-ce
|
||||||
|
- docker-ce-cli
|
||||||
|
- containerd.io
|
||||||
|
- docker-buildx-plugin
|
||||||
|
- docker-compose-plugin
|
||||||
|
# kubernetes
|
||||||
|
- kubeadm
|
||||||
|
- kubelet
|
||||||
|
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
kubernetes:
|
||||||
|
source: "deb https://pkgs.k8s.io/core:/stable:/v1.32/deb/ /"
|
||||||
|
keyid: "DE15B14486CD377B9E876E1A234654DA9A296436"
|
||||||
|
filename: kubernetes.list
|
||||||
|
docket:
|
||||||
|
source: "deb https://download.docker.com/linux/ubuntu noble stable"
|
||||||
|
keyid: "9DC858229FC7DD38854AE2D88D81803C0EBFCD88"
|
||||||
|
filename: docker.list
|
||||||
|
|
||||||
|
runcmd:
|
||||||
|
- apt-mark hold kubelet kubeadm kubectl
|
||||||
|
- systemctl stop kubelet
|
||||||
|
- containerd config default | sudo tee /etc/containerd/config.toml
|
||||||
|
- systemctl restart containerd
|
||||||
|
- ${k8s_join_command}
|
||||||
|
- systemctl enable kubelet
|
||||||
|
- systemctl start kubelet
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ variable "template_id" {
|
||||||
variable "template_name" { type = string }
|
variable "template_name" { type = string }
|
||||||
variable "snippet_name" { type = string }
|
variable "snippet_name" { type = string }
|
||||||
variable "user_passwd" { type = string } # hashed pw
|
variable "user_passwd" { type = string } # hashed pw
|
||||||
|
variable "k8s_join_command" {
|
||||||
|
type = string
|
||||||
|
default = ""
|
||||||
|
}
|
||||||
|
|
||||||
# SSH connection to Proxmox
|
# SSH connection to Proxmox
|
||||||
resource "null_resource" "create_template_remote" {
|
resource "null_resource" "create_template_remote" {
|
||||||
|
|
@ -56,7 +60,7 @@ resource "null_resource" "upload_cloud_init" {
|
||||||
|
|
||||||
provisioner "file" {
|
provisioner "file" {
|
||||||
destination = "/var/lib/vz/snippets/${var.snippet_name}"
|
destination = "/var/lib/vz/snippets/${var.snippet_name}"
|
||||||
content = templatefile("${path.module}/cloud_init.yaml", { authorized_ssh_key = file("~/.ssh/id_ed25519.pub"), passwd = var.user_passwd })
|
content = templatefile("${path.module}/cloud_init.yaml", { authorized_ssh_key = file("~/.ssh/id_ed25519.pub"), passwd = var.user_passwd, k8s_join_command = var.k8s_join_command })
|
||||||
}
|
}
|
||||||
|
|
||||||
triggers = {
|
triggers = {
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,18 @@ variable "ssh_keys" {
|
||||||
default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDHLhYDfyx237eJgOGVoJRECpUS95+7rEBS9vacsIxtx devvm"
|
default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDHLhYDfyx237eJgOGVoJRECpUS95+7rEBS9vacsIxtx devvm"
|
||||||
}
|
}
|
||||||
variable "bridge" { type = string }
|
variable "bridge" { type = string }
|
||||||
|
variable "vlan_tag" {
|
||||||
|
type = string
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
variable "vmid" {
|
||||||
|
type = number
|
||||||
|
default = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
resource "proxmox_vm_qemu" "cloudinit-vm" {
|
resource "proxmox_vm_qemu" "cloudinit-vm" {
|
||||||
vmid = 305
|
vmid = var.vmid
|
||||||
name = var.vm_name
|
name = var.vm_name
|
||||||
target_node = "pve"
|
target_node = "pve"
|
||||||
agent = 0
|
agent = 0
|
||||||
|
|
@ -47,6 +55,7 @@ resource "proxmox_vm_qemu" "cloudinit-vm" {
|
||||||
ipconfig0 = "ip=dhcp,ip6=dhcp"
|
ipconfig0 = "ip=dhcp,ip6=dhcp"
|
||||||
skip_ipv6 = true
|
skip_ipv6 = true
|
||||||
ciuser = "root"
|
ciuser = "root"
|
||||||
|
cipassword = "root"
|
||||||
sshkeys = var.ssh_keys
|
sshkeys = var.ssh_keys
|
||||||
searchdomain = "viktorbarzin.lan"
|
searchdomain = "viktorbarzin.lan"
|
||||||
onboot = true # start on node boot
|
onboot = true # start on node boot
|
||||||
|
|
@ -86,5 +95,6 @@ resource "proxmox_vm_qemu" "cloudinit-vm" {
|
||||||
bridge = var.bridge
|
bridge = var.bridge
|
||||||
model = "e1000"
|
model = "e1000"
|
||||||
macaddr = var.vm_mac_address
|
macaddr = var.vm_mac_address
|
||||||
|
tag = var.vlan_tag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue