Code Monkey home page Code Monkey logo

hyperv-csi-driver's Introduction

CSI HyperV Driver

This repository hosts the CSI HyperV driver and all of its build and dependent configuration files to deploy the driver.

Information

The driver connects to the HyperV Host, creates a VirtualDisk and attaches it to the requested VirtualMachine.

Pre-requisite

  • A HyperV Failover cluster or share nothing HyperV array
  • Kubernete cluster with nodes running nested on HyperV
  • All Kubernetes nodes should have hyperv-daemons installed
  • Powershell 6+ should to be installed on all HyperV hosts
  • SSHd (OpenSSH server) need to be running on all HyperV hosts
  • It should be possible to connect from the csi-driver container to all HyperV hosts with Powershell over SSH transport
  • one SSH PupPrivkey

Install requisites

HyperV Host: OpernSSH Server and Powershell Core

on each HyperV Host run in powershell:

#install sshd
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'

#to check the filewall rule
Get-NetFirewallRule -Name *ssh*

#install pwsh
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

#workaround for some sshd bug
New-Item -ItemType SymbolicLink -path C:\ -Name pwsh -Target "C:\Program Files\PowerShell\7"

Edit the sshd_config file located at $env:ProgramData\ssh.

PubkeyAuthentication yes
#PasswordAuthentication yes
Subsystem	powershell	c:/pwsh/pwsh.exe -sshs -NoLogo -NoProfile

more info under https://stackoverflow.com/questions/16212816/setting-up-openssh-for-windows-using-public-key-authentication

Edit or create the file $env:ProgramData\ssh\administrators_authorized_keys and add your personal ssh pubkey to the file. Ensure that only System and Administrators in the UAC permissions, or else sshd will not take it.

Restart ssdh with Restart-Service sshd

Test connection from your windows client:

Enter-PSSession <ServerFQDN> --SSHTransport -UserName Administrator

HyperV Host: Storage

Currently only ClusterStorageVolume is supported.

To enable storage of VirtualDisks on a CSV, create one subfolder "Volumes" on the CSV

The volume property "Storage" is to specify the CSV by name. C:\ClusterStorage\<Storage>\Volumes\<VolumeId>.vdhx

Kubernetes Node

centos/rhel:

#install hyperv kvp daemon
sudo yum install -y hyperv-daemons

#install pwsh
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
sudo yum install -y powershell

#edit /etc/ssh/sshd_config
#add: Subsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile

sudo shutdown -r now

ubuntu

sudo apt-get update
sudo apt-get install -y linux-cloud-tools-generic

sudo apt-get install -y powershell

#edit /etc/ssh/sshd_config
#add: Subsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile

sudo shutdown -r now

Optional add to all kubernetes VM's up to 4 scsi controllers one scsi controller supports 64 disks

SSH

create a new ssh key

ssh-keygen -a 100 -t ed25519 -f ~/path/to/local-ssh-keys -C "csi-hyperv"

ssh-keyscan -H -t ed25519 server1 server2 > ~/path/to/known_hosts
ssh-keyscan -H -t ed25519 server1.domain.local server2.domain.local >> ~/path/to/known_hosts

Deploy Kubernetes

create a ssh secret and deploy the driver

kubectl create secret generic csi-hyperv-key --from-file=id_ed25519=~/path/to/local-ssh-keys --from-file=known_hosts=~/path/to/known_hosts

#static namespace csi-hyperv
kubectl apply -f .\deploy\kubernetes-1.19\csi-hyperv\rbac.yaml
kubectl apply -f .\deploy\kubernetes-1.19\csi-hyperv\controller.yaml
kubectl apply -f .\deploy\kubernetes-1.19\csi-hyperv\node.yaml

Run example application and validate

To test connection from the container to the HyperV host servers

kubectl apply -f .\examples\pwsh-test.yaml

#after few moments
kubectl exec -it pwsh-test -- pwsh

#test with:
Enter-PSSession server1 -UserName administrator
Enter-PSSession server1.domain.local -UserName administrator

Confirm HyperV driver works

kubectl apply -f .\examples\csi-storageclass.yaml
kubectl apply -f .\examples\csi-pvc.yaml

#after few moments 
kubectl get pvc csi-pvc

#verify that the VirtualDisk on the storage was created
#ClusterStorage\<Storage>\Volumes\<VolumeId>.vhdx

#use the PVC as volume mount

Limitiations & Improvements

  • Currently only ClusterStorageVolumes are supported. The cluster storage can run over S2D or SOFS.
  • The support of a shared-nothing HyperV Host Array is technically possible, but not implemented.

Build

docker build

cd src
docker build -f hyperv-csi-driver\Dockerfile -t zetanova/hyperv-csi-driver:latest .
docker push zetanova/hyperv-csi-driver:latest

Deployment

running since Jan. 2020 tested up to kubernetes 1.20

hyperv-csi-driver's People

Contributors

dependabot[bot] avatar zetanova avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hyperv-csi-driver's Issues

appsettings.json usage

Hi,
This looks great, I am about to test it out (thank you for creating it), but I have a some questions about the appsettings values:
(1) Driver:Type Node or Controller - does it matter which is used? I am guessing it should be Controller but am not sure.
(2) Driver:Type:Controller - is this the path to CSV root(s)? i.e should I be putting c:\clusterstorage\MyCSV or something here?
(3) If the Administrator acount is disabled on my HV hosts, can I specify a local admin account name as a value for Username?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.