Skip to main content

Creating a Packer Worker Virtual Server

Objective: Create a Virtual Server on CoreWeave Cloud to create images with Hashicorp Packer.

Overview: This process consists of deploying an Ubuntu Virtual Server on CoreWeave Cloud, with the cloned PVC attached. The Virtual Server is then configured with a Docker image to run Packer. Note that this example assumes a cloned PVC was created as explained in the example Copying CoreWeave Images to a Writable PVC.

References:

Deploying Virtual Server

Using packer_vs.yaml, we will deploy our Virtual Server withkubectl create -f packer_vs.yaml:

title="packer_vs.yaml"
apiVersion: virtualservers.coreweave.com/v1alpha1
kind: VirtualServer
metadata:
name: packer-worker
namespace: tenant-<tenant>
spec:
region: ORD1
os:
type: linux
resources:
cpu:
type: amd-epyc-rome
count: 8
memory: 32Gi
storage:
root:
size: 256Gi
storageClassName: block-nvme-ord1
source:
pvc:
namespace: vd-images
name: ubuntu2004-docker-master-20210629-ord1
additionalDisks:
- name: winsvr2019std
spec:
persistentVolumeClaim:
claimName: winserver2019std-clone-20210701-ord1
users:
- username: <username>
password: <password>
network:
public: true
tcp:
ports:
- 22
initializeRunning: true
Tip

Note our region matches the region used when creating the cloned volume

kubectl get vs will show us our Virtual Server has been deployed, along with an IP we can use to SSH into:

Configuring Packer Environment

Using the external IP noted from kubectl get vs, connect to your Virtual Server via SSH. If you followed Copying CoreWeave Images to a Writable PVC, you'll notice our root disk is mounted to /dev/vda, and our cloned PVC is mounted to /dev/vdb:

Since our Virtual Server was created using ubuntu2004-docker-master-20210629-ord1, Docker is already installed. Running configure_packer_docker.sh will build a container to provide a consistent environment for using Packer, with all the dependencies installed.

title="configure_packer_docker.sh"
docker build -t "packer" -f - . <<EOF
FROM ubuntu:20.04
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
libc6-dev libvirt-daemon-system libvirt-dev python3-winrm \
qemu-kvm qemu-utils sshpass unzip curl wget git jq rsync \
genisoimage openssh-client libguestfs-tools \
yamllint moreutils ovmf
RUN wget -O /usr/local/bin/virtctl $(curl -L https://api.github.com/repos/kubevirt/kubevirt/releases/latest | grep browser_download_url.*-linux-amd64 | cut -d : -f 2,3| tr -d \")
RUN wget -O /usr/local/bin/kubectl https://dl.k8s.io/release/$(curl -L https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
RUN curl -L -s https://releases.hashicorp.com/packer/$(curl -L https://checkpoint-api.hashicorp.com/v1/check/packer | jq -r -M '.current_version')/packer_$(curl -L https://checkpoint-api.hashicorp.com/v1/check/packer | jq -r -M '.current_version')_linux_amd64.zip --output /tmp/packer_linux_amd64.zip
RUN unzip -o /tmp/packer_linux_amd64.zip -d /usr/local/bin/
RUN chmod +x /usr/local/bin/*ctl
RUN rm -rf /tmp/packer_linux_amd64.zip
VOLUME /work
WORKDIR /work
ENV LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1 PACKER_LOG=1
ENV PACKER_CACHE_DIR=/work/cache/packer
EOF