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
:
apiVersion: virtualservers.coreweave.com/v1alpha1kind: VirtualServermetadata:name: packer-workernamespace: tenant-<tenant>spec:region: ORD1os:type: linuxresources:cpu:type: amd-epyc-romecount: 8memory: 32Gistorage:root:size: 256GistorageClassName: block-nvme-ord1source:pvc:namespace: vd-imagesname: ubuntu2004-docker-master-20210629-ord1additionalDisks:- name: winsvr2019stdspec:persistentVolumeClaim:claimName: winserver2019std-clone-20210701-ord1users:- username: <username>password: <password>network:public: truetcp:ports:- 22initializeRunning: true
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.
docker build -t "packer" -f - . <<EOFFROM ubuntu:20.04RUN 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 ovmfRUN 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/kubectlRUN 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.zipRUN unzip -o /tmp/packer_linux_amd64.zip -d /usr/local/bin/RUN chmod +x /usr/local/bin/*ctlRUN rm -rf /tmp/packer_linux_amd64.zipVOLUME /workWORKDIR /workENV LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1 PACKER_LOG=1ENV PACKER_CACHE_DIR=/work/cache/packerEOF