Skip to content

Prepare the Hyper-V cluster

Create a domain account for the driver, e.g. EXAMPLE\k8s-hyperv-csi (password never expires, no interactive logon needed). It needs, on every node and on the cluster, one of:

Option Rights When
A. Local Administrators (simplest) Member of the local Administrators group on every node. That covers Hyper-V, the cluster (BUILTIN\Administrators has Full cluster access) and the CSV folders Production installations of Bare Metal Works run this way
B. Least privilege Member of Hyper-V Administrators on every node, Grant-ClusterAccess -User EXAMPLE\k8s-hyperv-csi -Full once on the cluster, Modify on the volume folders When local admin is not acceptable

Choose one folder per CSV for the VHDX files, e.g. C:\ClusterStorage\VStore1\k8s-volumes. The folder name becomes PvcFolder in the WebApi settings. The driver never writes outside these folders.

Copy Install-HypervCsiHost.ps1 and Test-HypervCsiHost.ps1 to each node and run them in an elevated PowerShell:

Terminal window
# installs OpenSSH Server, the pwsh 7 SSH subsystem, firewall rule, group membership, folder rights
.\Install-HypervCsiHost.ps1 -ServiceAccount 'EXAMPLE\k8s-hyperv-csi' `
-VolumeFolder 'C:\ClusterStorage\VStore1\k8s-volumes' `
-PowerShellMsi 'https://github.com/PowerShell/PowerShell/releases/download/v7.5.4/PowerShell-7.5.4-win-x64.msi' `
-LocalAdministrators # omit for option B
# read-only check, prints PASS/FAIL per item, exit code 1 on failure
.\Test-HypervCsiHost.ps1 -ServiceAccount 'EXAMPLE\k8s-hyperv-csi' -VolumeFolder 'C:\ClusterStorage\VStore1\k8s-volumes'

What the install script configures, if you prefer to do it by hand:

  1. Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0, service sshd Automatic and running, inbound firewall rule TCP 22.
  2. PowerShell 7 at C:\Program Files\PowerShell\7 (MSI).
  3. In C:\ProgramData\ssh\sshd_config:
    Subsystem powershell c:/progra~1/powershell/7/pwsh.exe -sshs -nologo -NoProfile
    then Restart-Service sshd. For Kerberos also GSSAPIAuthentication yes.
  4. The service account in Hyper-V Administrators (or Administrators).
  5. Modify for the service account on each volume folder.

For option B, additionally once per cluster: Grant-ClusterAccess -User EXAMPLE\k8s-hyperv-csi -Full.

Strongly recommended. The cluster configuration refresh after a drive change runs on the Hyper-V node with the service account’s credentials, which needs a Kerberos ticket on the node (a second hop). The WebApi obtains a ticket from a keytab and the SSH client forwards it (GSSAPIDelegateCredentials yes).

Without Kerberos (RemotingMethod: SshKey) provisioning, attach and detach still work, but every drive change logs Update-ClusterVirtualMachineConfiguration ... could not be completed and the cluster’s copy of the VM configuration is not refreshed until the next refresh from another source. Do not run production that way.

Create the keytab on a domain controller (sets the account password to the one you type):

ktpass /princ k8s-hyperv-csi@EXAMPLE.COM /mapuser EXAMPLE\k8s-hyperv-csi /pass * ^
/crypto AES256-SHA1 /ptype KRB5_NT_PRINCIPAL /out csi-service.keytab

krb5.conf for the WebApi (realm and KDCs of your domain; forwardable is required for delegation):

[libdefaults]
default_realm = EXAMPLE.COM
dns_lookup_kdc = true
forwardable = true
rdns = false
[realms]
EXAMPLE.COM = { kdc = dc-01.example.com kdc = dc-02.example.com }
[domain_realm]
.example.com = EXAMPLE.COM

On every node sshd_config needs GSSAPIAuthentication yes (the check script reports it), and the node’s SPN host/<fqdn> must exist, which is the case for domain-joined servers.

  • Service account created, rights per option A or B
  • Test-HypervCsiHost.ps1 passes on every node
  • Volume folder exists on every CSV you will use
  • Keytab and krb5.conf ready (Kerberos), or an SSH key pair whose public key is in the service account’s authorized_keys on every node (SshKey)
  • From the WebApi host: ssh k8s-hyperv-csi@hv-01.example.com works and ssh-keyscan output of all nodes is saved to known_hosts