我在用着Telmate 的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 连接到控制台,虚拟机会显示 IP 地址是通过 DHCP 接收的,而不是我提供的。此外,SSH 密钥不起作用,因此我无法连接到虚拟机进行故障排除。
如果我注释掉该cicustom
行,并仅依赖ipconfig0
和其他常规选项,则虚拟机会启动,我的 SSH 密钥确实会起作用。但是,指定的 IP 地址仍未使用;虚拟机只是使用 DHCP 提供的 IP 地址。尽管能够访问虚拟机,但我仍然想使用自定义 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
使用 Telmate 的提供程序针对 Flatcar 模板时生成的。
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
是使用Telmate 提供程序的 EDIT 4 中的第一个输出的整个 Systemd 日志。
编辑 7:---------------------------------------------------------
这些qm
命令使用 生成一个可运行的 Flatcar VM 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
似乎不起作用。