PowerShell script to deploy Kubernetes cluster on Microsoft Hyper-V Server
forked from https://github.com/nvtienanh/hyperv-k8s and customized for my own use on a stand alone windows 2022 server.
winget install --id Git.Git -e --source winget
✅Hyper-V server:
- Generate SSH Public key
ssh-keygen
✅Windows client:
- Run PowerShell as Admin
- Go to Window Admin Center download public ssh key and save to
$Home\.ssh
- Download and setup Qemu-Img portable
cd to $Home\hyperkube
curl https://cloudbase.it/downloads/qemu-img-win-x64-2_3_0.zip -o qemu-img.zip
7z x .\qemu-img.zip
set-executionpolicy remotesigned
del .\hyperkube.ps1
curl https://raw.githubusercontent.com/mkronvold/hyperkube/main/hyperkube.ps1 -o hyperkube.ps1
.\hyperkube.ps1 Get-Image
.\hyperkube.ps1 Save-ISOMaster
.\hyperkube.ps1 Save-ISONode1
✅Windows hyper-v server (can be same machine):
- Upload created isos (on Windows client) to
C:\Users\${username}\hyperkube
- Run PowerShell as Administrator
cd $Home\hyperkube
curl https://raw.githubusercontent.com/mkronvold/hyperkube/main/hyperkube.ps1 -o hyperkube.ps1
.\hyperkube.ps1 Install-Tools
.\hyperkube.ps1 Deploy-HostsFile
.\hyperkube.ps1 Deploy-Network
.\hyperkube.ps1 Get-Image
.\hyperkube.ps1 Deploy-Master
.\hyperkube.ps1 Deploy-Node1
.\hyperkube.ps1 Initialize-Kubeadm
.\hyperkube.ps1 Start-KubeadmJoin
.\hyperkube.ps1 Save-KubeConfig
You have to Start Powershell as administartor and run command set-executionpolicy remotesigned
. It make all scripts and configuration files downloaded from the Internet are signed by a trusted publisher.
Install-Tools
: Install packages kubectl, docker, qemu-imgShow-Config
: show script config varsDeploy-Network
: install private or public host networkDeploy-HostsFile
: append private network node names to etc/hostsGet-Image
: download the VM imageDeploy-Master
: create and launch master nodeDeploy-NodeN
: create and launch worker node (node1, node2, ...)Save-ISOMaster
: save master nodeSave-ISONodeN
: save worker node (node1, node2, ...)Get-Info
: display info about nodesInitialize-Kubeadm
: Initialize kubeadmStart-KubeadmJoin
: Run Kubeadm joind commandSave-KubeConfig
: Save Kube config to hostRestart-K8sVM
: Soft-reboot the nodesShutdown-K8sVM
: Soft-shutdown the nodesSave-K8sVM
: Snapshot the VMsRestore-K8sVM
: Restore VMs from latest snapshotsStop-K8sVM
: Stop the VMsStart-K8sVM
: Start the VMsRemove-K8sVM
: Stop VMs and delete the VM filesRemove-Network
: Delete the network