No description
Find a file
2021-12-11 19:01:05 +01:00
docs added digitalocean cluster 2021-08-11 22:52:11 +02:00
patches updated patches 2021-11-28 16:59:44 +01:00
vendor initial commit 2020-06-01 12:18:20 +02:00
.gitignore fixed pool search 2020-06-04 22:40:38 +02:00
client.go linter fixes 2021-11-07 11:57:25 +01:00
go.mod initial commit 2020-06-01 12:18:20 +02:00
go.sum initial commit 2020-06-01 12:18:20 +02:00
helper.go added clout init image docs 2020-11-01 20:09:16 +01:00
ipconfig.go added mtu 2021-04-17 19:56:27 +02:00
LICENSE initial commit 2020-06-01 12:18:20 +02:00
MINIMAL.md added minimal image 2021-12-11 19:01:05 +01:00
network.go added mtu 2021-04-17 19:56:27 +02:00
node.go added better id handling 2021-12-10 20:33:20 +01:00
pool.go added better id handling 2021-12-10 20:33:20 +01:00
README.md added ubuntu 20.04 2021-12-10 23:56:09 +01:00
scheme.go added better id handling 2021-12-10 20:33:20 +01:00
server.go added better id handling 2021-12-10 20:33:20 +01:00
serverstatus.go addes error status 2021-04-10 17:59:37 +02:00
snippet.go added clout init image docs 2020-11-01 20:09:16 +01:00
task.go linter fixes 2021-11-07 11:57:25 +01:00
TODO added minimal image 2021-12-11 19:01:05 +01:00
userdata.go linter fixes 2021-11-07 11:57:25 +01:00

pve-go

PVE-Go is a go library for the Proxmox VE API.

The design is based on the Hetzner Clound API implementation: https://github.com/hetznercloud/hcloud-go

Cloud-Init Image

How to prepare a cloud-init image.

Ubuntu 20.04

Download the latest version of the base image to one of your proxmox nodes:

curl -sSL https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img >/tmp/focal-server-cloudimg-amd64.img

Create a cloud-init config to bootstrap the template:

cat <<'EOF'> /var/lib/vz/snippets/9002_bootstrap
#cloud-config
package_update: true
package_upgrade: true
ntp:
  enabled: true
  servers: ["pool.ntp.org"]
ssh_deletekeys: true
ssh_genkeytypes: ["ed25519", "rsa"]
runcmd:
- "apt-get -y clean"
- "apt-get -y autoremove --purge"
- "bash -c 'rm /home/ubuntu/.ssh/authorized_keys; exit 0'"
- "bash -c 'find /var/log -type f | while read f; do echo -ne >$f; done; exit 0'"
- "bash -c 'rm -rf /var/lib/cloud/* /var/tmp/* /tmp/* /tmp/.*-unix; exit 0'"
power_state:
  mode: poweroff
EOF

Create the template VM:

qm stop 9002; qm destroy 9002
qm create 9002 --name ubuntu-2004 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9002 /tmp/focal-server-cloudimg-amd64.img local
qm set 9002 --scsihw virtio-scsi-pci --scsi0 local:9002/vm-9002-disk-0.raw
qm set 9002 --ide0 local:cloudinit
qm set 9002 --boot c --bootdisk scsi0
qm set 9002 --serial0 socket --vga serial0
qm set 9002 --cicustom "user=local:snippets/9002_bootstrap"
qm set 9002 --ipconfig0 ip=dhcp,ip6=dhcp

qm start 9002
sleep 10;while :; do qm status 9002|grep -q stopped && break; done
qm set 9002 --cicustom ""
qm set 9002 --ipconfig0 ""
qm template 9002

More Image Cleanup

mkdir /etc/systemd/system/motd-news.service.d
cat <<EOF>/etc/systemd/system/motd-news.service.d/override.conf
[Service]
ExecStart=/bin/true
EOF

mkdir /etc/systemd/timesyncd.conf.d
cat <<EOF>/etc/systemd/timesyncd.conf.d/ntp.conf
[Time]
NTP=pool.ntp.org
EOF

apt -y purge alsa-topology-conf alsa-ucm-conf apport \
  apport-symptoms at bash-completion bolt byobu eatmydata command-not-found \
  eject fonts-ubuntu-console htop install-info landscape-common lxd-agent-loader \
  motd-news-config nano ntfs-3g pastebinit plymouth plymouth-theme-ubuntu-text \
  popularity-contest policykit-1 python3-apport os-prober snapd \
  sound-theme-freedesktop ubuntu-advantage-tools ufw

# optional
# apt -y purge accountsservice multipath-tools packagekit udisks2 unattended-upgrades

apt -y autoremove

Even more cleanup:

apt -y purge lshw lsof ltrace man-db manpages mdadm mtr-tiny screen sosreport strace tcpdump tmux usbutils whiptail
apt -y autoremove

Ubuntu 18.04

Download the latest version of the base image to one of your proxmox nodes:

curl -sSL https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img >/tmp/bionic-server-cloudimg-amd64.img

Create a cloud-init config to bootstrap the template:

cat <<'EOF'> /var/lib/vz/snippets/9000_bootstrap
#cloud-config
package_update: true
package_upgrade: true
ntp:
  enabled: true
  servers: ["pool.ntp.org"]
ssh_deletekeys: true
ssh_genkeytypes: ["ed25519", "rsa"]
runcmd:
- "apt-get -y clean"
- "apt-get -y autoremove --purge"
- "bash -c 'rm /home/ubuntu/.ssh/authorized_keys; exit 0'"
- "bash -c 'find /var/log -type f | while read f; do echo -ne >$f; done; exit 0'"
- "bash -c 'rm -rf /var/lib/cloud/*; exit 0'"
power_state:
  mode: poweroff
EOF

Create the template VM:

qm stop 9000; qm destroy 9000
qm create 9000 --name ubuntu-1804 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9000 /tmp/bionic-server-cloudimg-amd64.img local
qm set 9000 --scsihw virtio-scsi-pci --scsi0 local:9000/vm-9000-disk-0.raw
qm set 9000 --ide0 local:cloudinit
qm set 9000 --boot c --bootdisk scsi0
qm set 9000 --serial0 socket --vga serial0
qm set 9000 --cicustom "user=local:snippets/9000_bootstrap"
qm set 9000 --ipconfig0 ip=dhcp,ip6=dhcp

qm start 9000
sleep 10;while :; do qm status 9000|grep -q stopped && break; done
qm set 9000 --cicustom ""
qm set 9000 --ipconfig0 ""
qm template 9000

More Image Cleanup

apt -y purge apport apport-symptoms bash-completion byobu htop landscape-common lxcfs lxd lxd-client motd-news-config nano ntfs-3g os-prober ufw
apt -y autoremove

Even more cleanup:

apt -y purge lshw lsof ltrace man-db manpages mdadm mtr-tiny screen sosreport strace tcpdump tmux usbutils whiptail
apt -y autoremove

Minimal Cloud Image

Ubuntu 20.04

curl -sSL https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img >/tmp/focal-server-cloudimg-amd64.img

cat <<'EOF'> /var/lib/vz/snippets/9002_bootstrap
#cloud-config
package_update: true
package_upgrade: true
ssh_deletekeys: true
ssh_genkeytypes: ["ed25519", "rsa"]
runcmd:
- "curl -sSL https://git.giftfish.de/ston1th/cleanup/raw/branch/master/ubuntu_2004_full.sh >/tmp/cleanup.sh"
- |
  bash -c '[ "$(sha256sum /tmp/cleanup.sh|cut -d" " -f1)" = "fe2827d03ebba6e058ed7b9e56116eef78a45606f2e5f2956b2b2f495f042724" ] && sh /tmp/cleanup.sh || echo "error: cleanup script hash does not match" >&2'
power_state:
  mode: poweroff
EOF

qm stop 9002; qm destroy 9002
qm create 9002 --name ubuntu-2004 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9002 /tmp/focal-server-cloudimg-amd64.img local
qm set 9002 --scsihw virtio-scsi-pci --scsi0 local:9002/vm-9002-disk-0.raw
qm set 9002 --ide0 local:cloudinit
qm set 9002 --boot c --bootdisk scsi0
qm set 9002 --serial0 socket --vga serial0
qm set 9002 --cicustom "user=local:snippets/9002_bootstrap"
qm set 9002 --ipconfig0 ip=dhcp,ip6=dhcp

qm start 9002
sleep 10;while :; do qm status 9002|grep -q stopped && break; done
qm set 9002 --cicustom ""
qm set 9002 --ipconfig0 ""
qm template 9002

Ubuntu 18.04

curl -sSL https://cloud-images.ubuntu.com/minimal/releases/bionic/release/ubuntu-18.04-minimal-cloudimg-amd64.img >/tmp/ubuntu-18.04-minimal-cloudimg-amd64.img

cat <<'EOF'> /var/lib/vz/snippets/9001_bootstrap
#cloud-config
package_update: true
package_upgrade: true
ntp:
  enabled: true
  servers: ["pool.ntp.org"]
ssh_deletekeys: true
ssh_genkeytypes: ["ed25519", "rsa"]
runcmd:
- "curl -sSL https://git.giftfish.de/ston1th/cleanup/raw/branch/master/ubuntu_1804.sh >/tmp/cleanup.sh"
- |
  bash -c '[ "$(sha256sum /tmp/cleanup.sh|cut -d" " -f1)" = "ecb2ae04cdd6b91fdc56a5db2015f401e474196b8eaaaf8e3aa5dc4b5e4c087d" ] && sh /tmp/cleanup.sh || echo "error: cleanup script hash does not match" >&2'
power_state:
  mode: poweroff
EOF

qm stop 9001; qm destroy 9001
qm create 9001 --name ubuntu-1804-min --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9001 /tmp/ubuntu-18.04-minimal-cloudimg-amd64.img local
qm set 9001 --scsihw virtio-scsi-pci --scsi0 local:9001/vm-9001-disk-0.raw
qm set 9001 --ide0 local:cloudinit
qm set 9001 --boot c --bootdisk scsi0
qm set 9001 --serial0 socket --vga serial0
qm set 9001 --cicustom "user=local:snippets/9001_bootstrap"
qm set 9001 --ipconfig0 ip=dhcp,ip6=dhcp

qm start 9001
sleep 10;while :; do qm status 9001|grep -q stopped && break; done
qm set 9001 --cicustom ""
qm set 9001 --ipconfig0 ""
qm template 9001