我在用著特爾瑪特的Terraform 提供者普羅克斯莫克斯並嘗試部署平車Linux虛擬機器使用雲端初始化透過傳遞文件客戶客製化。基於他們的例子,我製作了以下 Terraform 檔案:
variable "pve_user" {
}
variable "pve_password" {
}
variable "pve_host" {
}
provider "proxmox" {
pm_tls_insecure = true
pm_api_url = "https://SNIP/api2/json"
pm_user = "SNIP"
pm_password = "SNIP"
pm_parallel = 4
}
resource "null_resource" "cloud_init_config_files" {
connection {
type = "ssh"
user = var.pve_user
password = var.pve_password
host = var.pve_host
}
provisioner "file" {
source = "./templates/cloud-config.yml"
destination = "/var/lib/vz/snippets/cloud-config.yml"
}
}
resource "proxmox_vm_qemu" "k8s-masters" {
depends_on = [
null_resource.cloud_init_config_files
]
count = 1
name = "VM-${count.index}"
clone = "VM-Template"
full_clone = true
target_node = "192.168.20.10"
pool = "VM"
cores = 2
sockets = 1
memory = 10240
network {
id = 0
model = "virtio"
bridge = "vmbr0"
tag = 50
}
disk {
id = 0
type = "scsi"
size = 30
storage = "Pool"
storage_type = "zfspool"
backup = true
iothread = true
}
onboot = true
agent = 1
os_type = "cloud-init"
ssh_user = "core"
cicustom = "user=local:snippets/cloud-config.yml"
ipconfig0 = "ip=192.168.50.10/24,gw=192.168.50.1"
sshkeys = "ssh-rsa SNIP"
ssh_private_key = <<EOF
-----BEGIN RSA PRIVATE KEY-----
SNIP
-----END RSA PRIVATE KEY-----
EOF
}
運作後terraform apply
,虛擬機器建立成功,Flatcar 啟動。但是,如果您透過 Proxmox 連接到控制台,VM 會顯示 IP 位址是透過 DHCP 接收的,而不是我提供的。此外,SSH 金鑰不起作用,因此我無法連接到虛擬機器進行故障排除。
如果我註解掉該cicustom
行,並簡單地依賴ipconfig0
其他正常選項,虛擬機器就會出現,而我的 SSH 金鑰實際上可以工作。但指定的IP位址仍未被使用; VM 僅使用 DHCP 提供的一種。儘管能夠存取虛擬機,我仍然想使用自訂的 Cloud Init 設定文件,這樣我就可以存取更強大的配置選項。
我嘗試過我的cloud-config.yml
文件的各種組合。包括簡單的事情:
hostname: test
更詳細的事情,例如:
storage:
files:
- path: /opt/file1
filesystem: root
contents:
inline: Hello, world!
mode: 0644
user:
id: 500
group:
id: 501
passwd:
users:
- name: core
ssh_authorized_keys:
- ssh-rsa SNIP
儘管如此,我的 SSH 金鑰在我傳遞某些內容後就永遠不會工作cicustom
,並且基於主機名稱從未被操縱的事實,我假設 Cloud Init 根本沒有接收到自訂設定檔。我嘗試過傳遞兩者Ignition 和容器 Linux 配置格式化的檔案。
Flatcar Linux 因 Proxmox/cicustom 而損壞?在 Google 上搜尋諸如"flatcar" "proxmox"
、"coreos" "proxmox"
、"container linux" "proxmox"
、"flatcar" "cicustom"
等內容似乎沒有得到太多結果。我想沒有很多人將雲端原生作業系統與裸機連結起來?呵呵呵呵
然而,出現的是這個有趣的腳本。第 104-132 行討論為 Proxmox 建立 Flatcar/CoreOS 範本。那麼至少其他人之前已經這樣做過嗎?誰知道他們之後是否傳入了自訂雲初始化設定檔?
有任何想法嗎?
編輯: - - - - - - - - - - - - - - - - - - - - - - - - ------------
user-configdrive
未通過時新增了來自 systemd 單元的日誌cicustom
Aug 20 16:22:17 localhost coreos-cloudinit[831]: 2020/08/20 16:22:17 Checking availability of "cloud-drive"
Aug 20 16:22:17 localhost coreos-cloudinit[831]: 2020/08/20 16:22:17 Fetching user-data from datasource of type "cloud-drive"
Aug 20 16:22:17 localhost coreos-cloudinit[831]: 2020/08/20 16:22:17 Attempting to read from "/media/configdrive/openstack/latest/user_data"
Aug 20 16:22:17 localhost coreos-cloudinit[831]: 2020/08/20 16:22:17 line 6: warning: unrecognized key "chpasswd"
Aug 20 16:22:17 localhost coreos-cloudinit[831]: 2020/08/20 16:22:17 line 9: warning: incorrect type for "users[0]" (want struct)
Aug 20 16:22:17 localhost coreos-cloudinit[831]: 2020/08/20 16:22:17 line 10: warning: unrecognized key "package_upgrade"
Aug 20 16:22:17 localhost coreos-cloudinit[831]: 2020/08/20 16:22:17 Fetching meta-data from datasource of type "cloud-drive"
Aug 20 16:22:17 localhost coreos-cloudinit[831]: 2020/08/20 16:22:17 Attempting to read from "/media/configdrive/openstack/latest/meta_data.json"
Aug 20 16:22:17 localhost coreos-cloudinit[831]: 2020/08/20 16:22:17 Attempting to read from "/media/configdrive/openstack/content/0000"
Aug 20 16:22:17 localhost coreos-cloudinit[831]: 2020/08/20 16:22:17 Parsing user-data as cloud-config
Aug 20 16:22:17 localhost coreos-cloudinit[831]: 2020/08/20 16:22:17 Merging cloud-config from meta-data and user-data
Aug 20 16:22:17 VM-0 coreos-cloudinit[831]: 2020/08/20 16:22:17 Set hostname to VM-0
Aug 20 16:22:17 VM-0 coreos-cloudinit[831]: 2020/08/20 16:22:17 Authorized SSH keys for core user
Aug 20 16:22:17 VM-0 coreos-cloudinit[831]: 2020/08/20 16:22:17 Failed to apply cloud-config: Invalid option to manage_etc_hosts
Aug 20 16:22:17 VM-0 systemd[1]: user-configdrive.service: Main process exited, code=exited, status=1/FAILURE
編輯2: ----------------------------------------------- ----------- ------------
新增了上述 Systemd 單元所引用的文件內容。
core@VM-0 ~ $ cat /media/configdrive/openstack/latest/user_data
#cloud-config
hostname: VM-0
manage_etc_hosts: true
ssh_authorized_keys:
- REDACTED
chpasswd:
expire: False
users:
- default
package_upgrade: true
正如您所指出的,manage_etc_hosts
Proxmox 在這裡將其設為 true。
core@VM-0 ~ $ cat /media/configdrive/openstack/content/0000
auto lo
iface lo inet loopback
dns_nameservers 192.168.1.100
dns_search example.com
auto eth0
iface eth0 inet static
address 192.168.50.10
netmask 255.255.255.0
gateway 192.168.50.1
此部分包含所有正確的網路配置,但全部被 DHCP 覆蓋,因此被忽略。
core@VM-0 ~ $ cat /media/configdrive/openstack/latest/meta_data.json
{
"uuid": "e61563c9057e9162c4e14d111fea171379170532",
"network_config": { "content_path": "/content/0000" }
}
編輯3: ----------------------------------------------- ----------- ------------
新增了我對自訂 Cloud Init 檔案的嘗試
manage_etc_hosts: false
hostname: "test"
ssh_authorized_keys:
- REDACTED
編輯4: ----------------------------------------------- ----------- ------------
我跟著本指南基本上直接使用 qemu 而不是使用 Proxmox 來完成相同的事情。使用:
這cloud-config.ign
:
{
"ignition": { "version": "2.2.0" },
"passwd": {
"users": [
{
"name": "core",
"sshAuthorizedKeys": [
"REDACTED"
]
}
]
},
"storage": {
"files": [{
"filesystem": "root",
"path": "/etc/hostname",
"mode": 420,
"contents": { "source": "data:,test" }
}]
}
}
或這個cloud-config.yml
:
hostname: test
passwd:
users:
- name: tj
ssh_authorized_keys:
- REDACTED
兩者產生相同的結果。無法連線的虛擬機,隨主機名稱一起旋轉localhost
。
編輯5: ----------------------------------------------- ----------- ------------
這些日誌是user-configdrive.service
在針對 Flatcar 範本使用 Telmate 的提供者時產生的。
Aug 21 21:41:50 localhost coreos-cloudinit[795]: 2020/08/21 21:41:50 Checking availability of "cloud-drive"
Aug 21 21:41:50 localhost coreos-cloudinit[795]: 2020/08/21 21:41:50 Fetching user-data from datasource of type "cloud-drive"
Aug 21 21:41:50 localhost coreos-cloudinit[795]: 2020/08/21 21:41:50 Attempting to read from "/media/configdrive/openstack/latest/user_data"
Aug 21 21:41:50 localhost coreos-cloudinit[795]: 2020/08/21 21:41:50 Fetching meta-data from datasource of type "cloud-drive"
Aug 21 21:41:50 localhost coreos-cloudinit[795]: 2020/08/21 21:41:50 Attempting to read from "/media/configdrive/openstack/latest/meta_data.json"
Aug 21 21:41:50 localhost coreos-cloudinit[795]: 2020/08/21 21:41:50 Attempting to read from "/media/configdrive/openstack/content/0000"
Aug 21 21:41:50 localhost coreos-cloudinit[795]: Detected an Ignition config. Exiting...
Aug 21 21:41:50 localhost systemd[1]: Started Load cloud-config from /media/configdrive.
編輯6: ----------------------------------------------- ----------- ------------
這裡cloud-config.ign
是在 EDIT 4 中與 Telmate 的提供者一起使用後的第一個輸出的整個 Systemd 日誌。
編輯7: ----------------------------------------------- ----------- ------------
這些qm
命令使用cicustom
.
qm create 101 --name test --cores 2 --memory 2048 --net0 "virtio,bridge=vmbr0"
qm set 101 --net0 "virtio,bridge=vmbr0,tag=50"
qm importdisk 101 /mnt/RAIDPool_Templates/template/iso/flatcar_production_qemu_image.img FlashPool
qm set 101 --scsihw virtio-scsi-pci --scsi0 FlashPool:vm-101-disk-0 --ide2 FlashPool:cloudinit --boot c --bootdisk scsi0 --serial0 /dev/tty0 --ipconfig0 ip=dhcp --citype configdrive2
qm set 101 --cicustom user=RAIDPool_Templates:snippets/user-data.yml
qm start 101
ssh -i ~/.ssh/sol.milkyway.kubernetes [email protected]
用戶資料.yml:
#cloud-config
hostname: test
manage_etc_hosts: true
ssh_authorized_keys:
- ssh-rsa REDACTED
chpasswd:
expire: False
users:
- default
package_upgrade: true
不過,將相同的內容傳遞user-data.yml
到資源cicustom
內proxmox_vm_qemu
似乎不起作用。