Use root user as API is missing some needed permissions

Also tweak the LXC container specs and move the hook script to it's own file
This commit is contained in:
Sivert V. Sæther 2024-10-21 09:45:23 +02:00
parent a9caeece85
commit 3ce33a2b7c
3 changed files with 36 additions and 31 deletions

14
init-kube.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
if [ "$2" = "post-start" ]; then
lxc-attach "$1" <<EOF
export PATH=/sbin:\$PATH
apk update
apk upgrade
openrc -s sshd status 2>&1 | grep 'does not exist' &> /dev/null
if [ $? -eq 0 ]; then
apk add openssh-server
openrc -s sshd start
rc-update add sshd
fi
EOF
fi

View File

@ -11,21 +11,13 @@ resource "proxmox_virtual_environment_file" "kube-init" {
datastore_id = var.datastore_id datastore_id = var.datastore_id
node_name = var.proxmox_node node_name = var.proxmox_node
file_mode = "0755" file_mode = "0755"
source_raw { source_file {
file_name = "kube-init.sh" path = "init-kube.sh"
data = <<-EOF
#!/bin/sh
apk update
apk upgrade
apk add openssh-server
rc-update add sshd
openrc -s sshd start
EOF
} }
} }
resource "proxmox_virtual_environment_container" "kube-masters" { resource "proxmox_virtual_environment_container" "kube-masters" {
# hook_script_file_id = "${var.datastore_id}:snippets/kube-init.sh" hook_script_file_id = "${var.datastore_id}:snippets/kube-init.sh"
vm_id = var.vmid + count.index + 10 vm_id = var.vmid + count.index + 10
node_name = var.proxmox_node node_name = var.proxmox_node
count = var.master_count count = var.master_count
@ -33,26 +25,25 @@ resource "proxmox_virtual_environment_container" "kube-masters" {
proxmox_virtual_environment_download_file.latest_alpine, proxmox_virtual_environment_download_file.latest_alpine,
proxmox_virtual_environment_file.kube-init proxmox_virtual_environment_file.kube-init
] ]
operating_system {
template_file_id = proxmox_virtual_environment_download_file.latest_alpine.id
type = "alpine"
}
initialization { initialization {
# hostname = data.external.master_kube.result.name
hostname = "kube-master-${tostring(count.index)}.kubes.42069.no" hostname = "kube-master-${tostring(count.index)}.kubes.42069.no"
user_account {
password = var.user_password
keys = var.ssh_keys
}
ip_config { ip_config {
ipv4 { ipv4 {
address = "dhcp" address = "dhcp"
} }
} }
user_account {
password = var.user_password
keys = var.ssh_keys
}
} }
network_interface { network_interface {
name = "eth0" name = "eth0"
} }
operating_system {
template_file_id = proxmox_virtual_environment_download_file.latest_alpine.id
type = "alpine"
}
startup { startup {
order = "1" order = "1"
} }
@ -67,26 +58,25 @@ resource "proxmox_virtual_environment_container" "kube-workers" {
proxmox_virtual_environment_download_file.latest_alpine, proxmox_virtual_environment_download_file.latest_alpine,
proxmox_virtual_environment_file.kube-init proxmox_virtual_environment_file.kube-init
] ]
operating_system {
template_file_id = proxmox_virtual_environment_download_file.latest_alpine.id
type = "alpine"
}
initialization { initialization {
# hostname = data.external.worker_kube.result.name
hostname = "kube-worker-${tostring(count.index)}.kubes.42069.no" hostname = "kube-worker-${tostring(count.index)}.kubes.42069.no"
user_account {
password = var.user_password
keys = var.ssh_keys
}
ip_config { ip_config {
ipv4 { ipv4 {
address = "dhcp" address = "dhcp"
} }
} }
user_account {
password = var.user_password
keys = var.ssh_keys
}
} }
network_interface { network_interface {
name = "eth0" name = "eth0"
} }
operating_system {
template_file_id = proxmox_virtual_environment_download_file.latest_alpine.id
type = "alpine"
}
startup { startup {
order = "3" order = "3"
} }

View File

@ -1,7 +1,8 @@
variable "api_token" {} variable "root_pwd" {}
variable "endpoint" {} variable "endpoint" {}
provider "proxmox" { provider "proxmox" {
api_token = var.api_token
endpoint = var.endpoint endpoint = var.endpoint
password = var.root_pwd
username = "root@pam"
insecure = true insecure = true
} }