How to Use Packer and Subiquity on WSL2

Background

My main dev environment is windows convenient WSL2, however the WSL2 instance is isolated from the host machines IP, leading to some issues when it comes to accessing ports WSL ports on my LAN. Specifically the issue I ran into was when building packer and automating my Ubuntu 20.04 install. After some research I found that restricting the subiquity port and port forwarding vis netsh successfully allows packers http server to be reached on my host machines LAN.

Code and Commands

First you need to edit your packer file to restrict the http ports to a single port so you can port forward.

I have included a sample .pkc.hcl file below, the static port configuration is achieved on code lines 30 and 31 by defining http_port_max and http_port_min

source “vsphere-iso” “this” {
vcenter_server = var.vsphere_server
username = var.vsphere_user
password = var.vsphere_password
datacenter = var.datacenter
cluster = var.cluster
insecure_connection = true
vm_name = “tf-ubuntu-server-20.04”
guest_os_type = “ubuntu64Guest”
ssh_username = “ubuntu”
ssh_password = “ubuntu”
ssh_timeout = “20m”
ssh_handshake_attempts = “50”
CPUs = 8
RAM = 4128
RAM_reserve_all = true
disk_controller_type = [“pvscsi”]
datastore = var.datastore
storage {
disk_size = 16384
disk_thin_provisioned = true
}
iso_paths = [“[iSCSI Raid-10] OS/ubuntu-20.04.2-live-server-amd64.iso”]
iso_checksum = “sha256:b23488689e16cad7a269eb2d3a3bf725d3457ee6b0868e00c8762d3816e25848”
http_directory = “subiquity/http”
http_port_max = 8336
http_port_min = 8336
network_adapters {
network = var.network_name
network_card = “vmxnet3”
}
boot_wait = “5s”
boot_command = [
” “,
“autoinstall net.ifnames=0 biosdevname=0 ip=dhcp ipv6.disable=1 ds=nocloud-net;seedfrom=http://192.168.0.168:{{ .HTTPPort }}/”,
“”
]
}
build {
sources = [
“source.vsphere-iso.this”
]
provisioner “shell” {
inline = [
“while [ ! -f /var/lib/cloud/instance/boot-finished ]; do sleep 5; done”,
“sudo rm /etc/netplan/*”,
“sudo sed -i ‘s/ip=dhcp//g’ /etc/default/grub”,
“sudo update-grub”,
“sudo apt -y purge cloud-init”
]
}
}

Next you will port forward the WLS2 port to your windows host machine with the below command in command prompt (as admin)

netsh interface portproxy add v4tov4 listenport=8336 listenaddress=0.0.0.0 connectport=8336 connectaddress=

Related Posts

Terraform Tips & Tricks – Part 1 – Building A Constant Reference

One of the most common problems I see in large organizations when working with terraform is consistency. When we have a large amount of resources being managed…

Istio Architecture Diagram

Everything You Ever Wanted to Know About Istio but Were Afraid to Ask

Istio is a powerful service mesh that integrates natively with Kubernetes, I have been using Istio as my service mesh, ingress, and egress gateways on my personal…

Envoy Modules Solar Monitoring Grafana Dashboard

How to Monitor Your Enphase Home Solar System with Telegraf

How to collect metrics from an Enphase Envoy PV system, with telegraf and influxdb.

Anthos on Bare Metal Architecture Diagram

How to Deploy Anthos on Bare Metal On-Prem

Introduction The main advantage of Anthos on BM over Anthos on VMWare for on-prem deployments is the ability to run Anthos clusters without a hypervisor license. Cluster…

OPA Gatekeeper Architecture

OPA Gatekeeper: Bringing Law and Order to Kubernetes

Introduction Open Policy Agent (OPA) is a policy based control agent that is able to be integrated on various platforms. For the sake of this document we…

Anthos GKE Cluster Traffic Diagram

How to Setup Anthos on GKE Autopilot with Private Certificate Authority

What You Will Create The guide will set up the following: 2 Private GKE autopilot clusters with master global access ASM with multicluster mesh IstioIngress gateway to…

Leave a Reply