https://rancher.com/ logo
Title
s

sticky-summer-13450

12/24/2022, 11:01 AM
Has anyone documented how to create / run / destroy a Harvester VM using
kubectl
? I’d like to script / automate the creation of CloudInit configured VMs in Harvester.
o

orange-policeman-97710

12/24/2022, 3:39 PM
Try to create a VM using UI and view the VM yaml which is allowed to be deployed by kubectl.
s

sticky-summer-13450

12/25/2022, 4:26 PM
The yaml of a VM does not include things like the CloudInit user and network data.
b

bland-farmer-13503

12/26/2022, 3:06 AM
Hi @sticky-summer-13450, we store cloudinit in secrets like:
- cloudInitNoCloud:
          networkDataSecretRef:
            name: vm-test-w8anf
          secretRef:
            name: vm-test-w8anf
        name: cloudinitdisk
apiVersion: v1
data:
  networkdata: ""
  userdata: I2Nsb3VkLWNvbmZpZwpwYXNzd29yZDogdGVzdApjaHBhc3N3ZDoKICBleHBpcmU6IGZhbHNlCnNzaF9wd2F1dGg6IHRydWUK
kind: Secret
metadata:
  creationTimestamp: "2022-12-26T02:59:48Z"
  labels:
    <http://harvesterhci.io/cloud-init-template|harvesterhci.io/cloud-init-template>: harvester
  name: vm-test-w8anf
  namespace: default
  ownerReferences:
  - apiVersion: <http://kubevirt.io/v1|kubevirt.io/v1>
    kind: VirtualMachine
    name: vm-test
    uid: e4f1a8f2-ff48-487d-8161-ed88efae93ac
  resourceVersion: "58593"
  uid: a315c846-3731-4011-ac12-d91b34e7266c
type: secret
s

sticky-summer-13450

12/26/2022, 10:49 AM
Thanks @bland-farmer-13503. Do I need to use specific labels or names? Is the use of
kubectl
to manage VMs in Harvester supported and documented?
b

bland-farmer-13503

12/27/2022, 2:40 AM
I think you don't need to use specific labels/names.
kubectl
management is not in Harvester document. If you want to control Harvester via command line tool, I suggest to use Harvester Terraform Provider. https://docs.harvesterhci.io/v1.1/terraform/
s

sticky-summer-13450

12/28/2022, 9:50 AM
I suggest to use Harvester Terraform Provider
Fantastic, another tool to learn over the holiday season 🙂 Thank you for the advice.