kubevirt / kubevirt

Kubernetes Virtualization API and runtime in order to define and manage virtual machines.
https://kubevirt.io
Apache License 2.0
5.5k stars 1.32k forks source link

Passing env/secret into a WindowsVM #11530

Closed Neoclassic closed 3 weeks ago

Neoclassic commented 6 months ago

I have a windows image ready in qcow2 format. Now I want to inject some configuration at startup. I tried configDrive but its not visible in the VM created. Any other way to achieve this ?

victortoso commented 6 months ago

Just to confirm with you, you tested this and it didn't work? https://kubevirt.io/user-guide/virtual_machines/startup_scripts/#cloud-init

Neoclassic commented 6 months ago

Yeah I tested this. But didn't work. I think windows does not support cloud-init.

victortoso commented 6 months ago

I expected that to work, just in case, what error do you see? Can you share the configuration you have tried?

akalenyu commented 6 months ago

This came up before at https://github.com/kubevirt/kubevirt/issues/7992#issuecomment-1171329507 maybe the author could share how he achieved it

Neoclassic commented 6 months ago
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: myvm
spec:
  running: true
  template:
    metadata:
      labels:
        kubevirt.io/domain: myvm
    spec:
      domain:
        cpu:
          cores: 4
        features:
          acpi: {}
          apic: {}
          hyperv:
            relaxed: {}
            vapic: {}
            spinlocks:
              spinlocks: 8191
        clock:
          utc: {}
          timer:
            hpet:
              present: false
            pit:
              tickPolicy: delay
            rtc:
              tickPolicy: catchup
            hyperv: {}
        devices:
          blockMultiQueue: true
          disks:
            - bootOrder: 1
              disk:
                bus: sata
              name: cdromiso
            - bootOrder: 2
              disk:
                bus: virtio
              name: virtiocontainerdisk
            - bootOrder: 3
              disk:
                bus: virtio
              name: disk3
            - bootOrder: 4
              disk:
                bus: virtio
              name: config-volume
        firmware:
          bootloader:
            efi:
              secureBoot: false
        machine:
          type: q35
        resources:
          requests:
            memory: 16G
      nodeSelector:
        beta.kubernetes.io/instance-type: m5.metal
      volumes:
      - name: cdromiso
        dataVolume:
          name: myvm
      - containerDisk:
          image: quay.io/kubevirt/virtio-container-disk
        name: virtiocontainerdisk

      - cloudInitNoCloud:
          userData: |
            manage_etc_hosts: true
            hostname: myvm
            bootcmd:
            - 'powershell.exe -ExecutionPolicy bypass -Command $env:CUSTOM_VAR="dakshverma"'
        name: disk3
      - name: config-volume
        configMap:
          name: windows-vm-env

This is the VM definition. There is no error as such, but i cant see the envs or any file containing config.

Neoclassic commented 6 months ago

testvm.log pod logs

Neoclassic commented 6 months ago

I think tekton-task will inject the env and secret at bake/build time. But requirement is to have them at deploy time.

kubevirt-bot commented 3 months ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

/lifecycle stale

kubevirt-bot commented 2 months ago

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

/lifecycle rotten

amartyaa commented 1 month ago

@Neoclassic You got any workaround for this.

fabiand commented 1 month ago

How would you folks expect this feature to work?

That an env var is set in every powershell in windows? Or that you can look at a file to understand all env vars? or … ?

amartyaa commented 1 month ago

How would you folks expect this feature to work?

That an env var is set in every powershell in windows?

Or that you can look at a file to understand all env vars?

or … ?

I think the ask is for a Start-UP script/Userdata kind of implementation for windows based kubevirt instances.

fabiand commented 1 month ago

I see. Well You can use sysprep. You can use cloud-init (witn CloudBaseIT Windows for example).

You can use guestfs to inject a startup script.

What is missing?

kubevirt-bot commented 3 weeks ago

Rotten issues close after 30d of inactivity. Reopen the issue with /reopen. Mark the issue as fresh with /remove-lifecycle rotten.

/close

kubevirt-bot commented 3 weeks ago

@kubevirt-bot: Closing this issue.

In response to [this](https://github.com/kubevirt/kubevirt/issues/11530#issuecomment-2335130703): >Rotten issues close after 30d of inactivity. >Reopen the issue with `/reopen`. >Mark the issue as fresh with `/remove-lifecycle rotten`. > >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.