diff --git a/Kubernetes/flannel/overlay/cni/config/cni.conf b/Kubernetes/flannel/overlay/cni/config/cni.conf index 5d4cf669..eb195b2d 100644 --- a/Kubernetes/flannel/overlay/cni/config/cni.conf +++ b/Kubernetes/flannel/overlay/cni/config/cni.conf @@ -1,36 +1,36 @@ -{ - "cniVersion": "0.2.0", - "name": "vxlan0", - "type": "flannel", - "delegate": { - "type": "overlay", - "dns": { - "Nameservers": [ - "11.0.0.10" - ], - "Search": [ - "svc.cluster.local" - ] - }, - "Policies": [ - { - "Name": "EndpointPolicy", - "Value": { - "Type": "OutBoundNAT", - "ExceptionList": [ - "192.168.0.0/16", - "11.0.0.0/8" - ] - } - }, - { - "Name": "EndpointPolicy", - "Value": { - "Type": "ROUTE", - "DestinationPrefix": "11.0.0.0/8", - "NeedEncap": true - } - } - ] - } -} +{ + "cniVersion": "0.2.0", + "name": "vxlan0", + "type": "flannel", + "delegate": { + "type": "win-overlay", + "dns": { + "Nameservers": [ + "11.0.0.10" + ], + "Search": [ + "default.svc.cluster.local" + ] + }, + "Policies": [ + { + "Name": "EndpointPolicy", + "Value": { + "Type": "OutBoundNAT", + "ExceptionList": [ + "192.168.0.0/16", + "11.0.0.0/8" + ] + } + }, + { + "Name": "EndpointPolicy", + "Value": { + "Type": "ROUTE", + "DestinationPrefix": "11.0.0.0/8", + "NeedEncap": true + } + } + ] + } +} diff --git a/Kubernetes/flannel/overlay/cni/overlay.exe b/Kubernetes/flannel/overlay/cni/overlay.exe deleted file mode 100644 index 7a517f89..00000000 Binary files a/Kubernetes/flannel/overlay/cni/overlay.exe and /dev/null differ diff --git a/Kubernetes/flannel/overlay/cni/win-overlay.exe b/Kubernetes/flannel/overlay/cni/win-overlay.exe new file mode 100644 index 00000000..b964a9f3 Binary files /dev/null and b/Kubernetes/flannel/overlay/cni/win-overlay.exe differ diff --git a/Kubernetes/flannel/overlay/flanneld.exe b/Kubernetes/flannel/overlay/flanneld.exe index 274c2756..95794b32 100644 Binary files a/Kubernetes/flannel/overlay/flanneld.exe and b/Kubernetes/flannel/overlay/flanneld.exe differ diff --git a/Kubernetes/flannel/overlay/start-kubelet.ps1 b/Kubernetes/flannel/overlay/start-kubelet.ps1 index 890f5882..8c8e20e6 100644 --- a/Kubernetes/flannel/overlay/start-kubelet.ps1 +++ b/Kubernetes/flannel/overlay/start-kubelet.ps1 @@ -6,7 +6,7 @@ Param( $NetworkMode = "Overlay" # Todo : Get these values using kubectl -$KubeDnsSuffix ="svc.cluster.local" +$KubeDnsSuffix ="default.svc.cluster.local" $KubeDnsServiceIp="11.0.0.10" $serviceCIDR="11.0.0.0/8" @@ -24,12 +24,12 @@ Update-CNIConfig($podCIDR) "name": "", "type": "flannel", "delegate": { - "type": "overlay", + "type": "win-overlay", "dns" : { "Nameservers" : [ "11.0.0.10" ], - "Search": [ "svc.cluster.local" ] + "Search": [ "default.svc.cluster.local" ] }, - "AdditionalArgs" : [ + "Policies" : [ { "Name" : "EndpointPolicy", "Value" : { "Type" : "OutBoundNAT", "ExceptionList": [ "", "" ] } }, @@ -44,14 +44,14 @@ Update-CNIConfig($podCIDR) $configJson = ConvertFrom-Json $jsonSampleConfig $configJson.type = "flannel" $configJson.name = $NetworkName - $configJson.delegate.type = "overlay" + $configJson.delegate.type = "win-overlay" $configJson.delegate.dns.Nameservers[0] = $KubeDnsServiceIp $configJson.delegate.dns.Search[0] = $KubeDnsSuffix - $configJson.delegate.AdditionalArgs[0].Value.ExceptionList[0] = $clusterCIDR - $configJson.delegate.AdditionalArgs[0].Value.ExceptionList[1] = $serviceCIDR + $configJson.delegate.Policies[0].Value.ExceptionList[0] = $clusterCIDR + $configJson.delegate.Policies[0].Value.ExceptionList[1] = $serviceCIDR - $configJson.delegate.AdditionalArgs[1].Value.DestinationPrefix = $serviceCIDR + $configJson.delegate.Policies[1].Value.DestinationPrefix = $serviceCIDR if (Test-Path $CNIConfig) { Clear-Content -Path $CNIConfig diff --git a/Kubernetes/flannel/overlay/start-kubeproxy.ps1 b/Kubernetes/flannel/overlay/start-kubeproxy.ps1 index 5c83d229..b24c62a7 100644 --- a/Kubernetes/flannel/overlay/start-kubeproxy.ps1 +++ b/Kubernetes/flannel/overlay/start-kubeproxy.ps1 @@ -1,16 +1,16 @@ -Param( - $NetworkName = "vxlan0", - $ManagementIP - -) - -$env:KUBE_NETWORK=$NetworkName.ToLower() - -$sourceVipJSON = Get-Content sourceVip.json | ConvertFrom-Json -$env:SOURCE_VIP= $sourceVipJSON.ip4.ip.Split("/")[0] - -$env:HOST_MAC=(Get-NetAdapter -InterfaceAlias (Get-NetIPAddress -IPAddress $ManagementIP).InterfaceAlias).MacAddress - -ipmo c:\k\hns.psm1 -Get-HnsPolicyList | Remove-HnsPolicyList -c:\k\kube-proxy.exe --v=4 --proxy-mode=kernelspace --hostname-override=$(hostname) --kubeconfig=c:\k\config +Param( + $NetworkName = "vxlan0", + $ManagementIP + +) +$networkName = $NetworkName.ToLower() + +If((Test-Path c:/k/sourceVip.json)) { + $sourceVipJSON = Get-Content sourceVip.json | ConvertFrom-Json + $sourceVip = $sourceVipJSON.ip4.ip.Split("/")[0] +} + +$hostMac=(Get-NetAdapter -InterfaceAlias (Get-NetIPAddress -IPAddress $ManagementIP).InterfaceAlias).MacAddress +ipmo c:\k\hns.psm1 +Get-HnsPolicyList | Remove-HnsPolicyList +c:\k\kube-proxy.exe --v=4 --proxy-mode=kernelspace --hostname-override=$(hostname) --kubeconfig=c:\k\config --network-name=$networkName --source-vip=$sourceVip --enable-dsr=false diff --git a/Kubernetes/flannel/overlay/start.ps1 b/Kubernetes/flannel/overlay/start.ps1 index 5423f80a..b819f3b4 100644 --- a/Kubernetes/flannel/overlay/start.ps1 +++ b/Kubernetes/flannel/overlay/start.ps1 @@ -17,7 +17,7 @@ function DownloadCniBinaries() md C:\etc\kube-flannel -ErrorAction Ignore DownloadFile -Url "https://github.com/Microsoft/SDN/raw/master/Kubernetes/flannel/overlay/cni/config/cni.conf" -Destination $BaseDir\cni\config\cni.conf - DownloadFile -Url "https://github.com/Microsoft/SDN/raw/master/Kubernetes/flannel/overlay/cni/overlay.exe" -Destination $BaseDir\cni\overlay.exe + DownloadFile -Url "https://github.com/Microsoft/SDN/raw/master/Kubernetes/flannel/overlay/cni/win-overlay.exe" -Destination $BaseDir\cni\win-overlay.exe DownloadFile -Url "https://github.com/Microsoft/SDN/raw/master/Kubernetes/flannel/l2bridge/cni/flannel.exe" -Destination $BaseDir\cni\flannel.exe DownloadFile -Url "https://github.com/Microsoft/SDN/raw/master/Kubernetes/flannel/l2bridge/cni/host-local.exe" -Destination $BaseDir\cni\host-local.exe DownloadFile -Url "https://github.com/Microsoft/SDN/raw/master/Kubernetes/flannel/overlay/net-conf.json" -Destination $BaseDir\net-conf.json diff --git a/Kubernetes/windows/helper.psm1 b/Kubernetes/windows/helper.psm1 index 3c89e589..3b456ebe 100644 --- a/Kubernetes/windows/helper.psm1 +++ b/Kubernetes/windows/helper.psm1 @@ -1,131 +1,122 @@ -function DownloadFile() -{ - param( - [parameter(Mandatory = $true)] $Url, - [parameter(Mandatory = $true)] $Destination - ) - - if (Test-Path $Destination) - { - Write-Host "File $Destination already exists." - return - } - - try { - (New-Object System.Net.WebClient).DownloadFile($Url,$Destination) - Write-Host "Downloaded $Url=>$Destination" - } catch { - Write-Error "Failed to download $Url" - throw - } -} - -function CleanupOldNetwork($NetworkName) -{ - $hnsNetwork = Get-HnsNetwork | ? Name -EQ $NetworkName.ToLower() - - if ($hnsNetwork) - { - # Cleanup all containers - docker ps -q | foreach {docker rm $_ -f} - - Write-Host "Cleaning up old HNS network found" - Write-Host ($hnsNetwork | ConvertTo-Json -Depth 10) - Remove-HnsNetwork $hnsNetwork - } -} - -function WaitForNetwork($NetworkName) -{ - # Wait till the network is available - while(!(Get-HnsNetwork | ? Name -EQ $NetworkName.ToLower())) - { - Write-Host "Waiting for the Network to be created" - Start-Sleep 1 - } -} - - -function -IsNodeRegistered() -{ - c:\k\kubectl.exe --kubeconfig=c:\k\config get nodes/$($(hostname).ToLower()) - return (!$LASTEXITCODE) -} - -function -RegisterNode() -{ - if (!(IsNodeRegistered)) - { - $argList = @("--hostname-override=$(hostname)","--pod-infra-container-image=kubeletwin/pause","--resolv-conf=""""", "--cgroups-per-qos=false", "--enforce-node-allocatable=""""","--kubeconfig=c:\k\config") - $process = Start-Process -FilePath c:\k\kubelet.exe -PassThru -ArgumentList $argList - - # Wait till the - while (!(IsNodeRegistered)) - { - Write-Host "waiting to discover node registration status" - Start-Sleep -sec 1 - } - - $process | Stop-Process | Out-Null - } - else - { - Write-Host "Node $(hostname) already registered" - } -} - -function StartFlanneld($ipaddress, $NetworkName) -{ - CleanupOldNetwork $NetworkName - - # Start FlannelD, which would recreate the network. - # Expect disruption in node connectivity for few seconds - pushd - cd C:\flannel\ - [Environment]::SetEnvironmentVariable("NODE_NAME", (hostname).ToLower()) - start C:\flannel\flanneld.exe -ArgumentList "--kubeconfig-file=C:\k\config --iface=$ipaddress --ip-masq=1 --kube-subnet-mgr=1" -NoNewWindow - popd - - WaitForNetwork $NetworkName -} - -function GetSourceVip($ipaddress, $NetworkName) -{ - - ipmo C:\k\HNS.V2.psm1 - $hnsNetwork = Get-HnsNetwork | ? Name -EQ $NetworkName.ToLower() - $subnet = $hnsNetwork.Subnets[0].AddressPrefix - - $ipamConfig = @" - {"ipam":{"type":"host-local","ranges":[[{"subnet":"$subnet"}]],"dataDir":"/var/lib/cni/networks/$NetworkName"}} -"@ - - $ipamConfig | Out-File "C:\k\sourceVipRequest.json" - - $env:CNI_COMMAND="ADD" - $env:CNI_CONTAINERID="dummy" - $env:CNI_NETNS="dummy" - $env:CNI_IFNAME="dummy" - $env:CNI_PATH="c:\k\cni" #path to host-local.exe - - If(!(Test-Path c:/k/sourceVip.json)){ - Get-Content sourceVipRequest.json | .\cni\host-local.exe | Out-File sourceVip.json - } - - $sourceVipJSON = Get-Content sourceVip.json | ConvertFrom-Json - New-HNSEndpoint -NetworkId $hnsNetwork.ID ` - -IPAddress $sourceVipJSON.ip4.ip.Split("/")[0] ` - -MacAddress "00-11-22-33-44-55" ` - -PAPolicy @{"PA" = $ipaddress; } ` - -Verbose -} - -Export-ModuleMember DownloadFile -Export-ModuleMember CleanupOldNetwork -Export-ModuleMember IsNodeRegistered -Export-ModuleMember RegisterNode -Export-ModuleMember WaitForNetwork -Export-ModuleMember GetSourceVip -Export-ModuleMember StartFlanneld \ No newline at end of file +function DownloadFile() +{ + param( + [parameter(Mandatory = $true)] $Url, + [parameter(Mandatory = $true)] $Destination + ) + + if (Test-Path $Destination) + { + Write-Host "File $Destination already exists." + return + } + + try { + (New-Object System.Net.WebClient).DownloadFile($Url,$Destination) + Write-Host "Downloaded $Url=>$Destination" + } catch { + Write-Error "Failed to download $Url" + throw + } +} + +function CleanupOldNetwork($NetworkName) +{ + $hnsNetwork = Get-HnsNetwork | ? Name -EQ $NetworkName.ToLower() + + if ($hnsNetwork) + { + # Cleanup all containers + docker ps -q | foreach {docker rm $_ -f} + + Write-Host "Cleaning up old HNS network found" + Write-Host ($hnsNetwork | ConvertTo-Json -Depth 10) + Remove-HnsNetwork $hnsNetwork + } +} + +function WaitForNetwork($NetworkName) +{ + # Wait till the network is available + while( !(Get-HnsNetwork -Verbose | ? Name -EQ $NetworkName.ToLower()) ) + { + Write-Host "Waiting for the Network to be created" + Start-Sleep 1 + } +} + + +function +IsNodeRegistered() +{ + c:\k\kubectl.exe --kubeconfig=c:\k\config get nodes/$($(hostname).ToLower()) + return (!$LASTEXITCODE) +} + +function +RegisterNode() +{ + if (!(IsNodeRegistered)) + { + $argList = @("--hostname-override=$(hostname)","--pod-infra-container-image=kubeletwin/pause","--resolv-conf=""""", "--cgroups-per-qos=false", "--enforce-node-allocatable=""""","--kubeconfig=c:\k\config") + $process = Start-Process -FilePath c:\k\kubelet.exe -PassThru -ArgumentList $argList + + # Wait till the + while (!(IsNodeRegistered)) + { + Write-Host "waiting to discover node registration status" + Start-Sleep -sec 1 + } + + $process | Stop-Process | Out-Null + } + else + { + Write-Host "Node $(hostname) already registered" + } +} + +function StartFlanneld($ipaddress, $NetworkName) +{ + CleanupOldNetwork $NetworkName + + # Start FlannelD, which would recreate the network. + # Expect disruption in node connectivity for few seconds + pushd + cd C:\flannel\ + [Environment]::SetEnvironmentVariable("NODE_NAME", (hostname).ToLower()) + start C:\flannel\flanneld.exe -ArgumentList "--kubeconfig-file=C:\k\config --iface=$ipaddress --ip-masq=1 --kube-subnet-mgr=1" -NoNewWindow + popd + + WaitForNetwork $NetworkName +} + +function GetSourceVip($ipaddress, $NetworkName) +{ + $hnsNetwork = Get-HnsNetwork | ? Name -EQ $NetworkName.ToLower() + $subnet = $hnsNetwork.Subnets[0].AddressPrefix + + $ipamConfig = @" + {"cniVersion": "0.2.0", "name": "vxlan0", "ipam":{"type":"host-local","ranges":[[{"subnet":"$subnet"}]],"dataDir":"/var/lib/cni/networks/$NetworkName"}} +"@ + + $ipamConfig | Out-File "C:\k\sourceVipRequest.json" + + $env:CNI_COMMAND="ADD" + $env:CNI_CONTAINERID="dummy" + $env:CNI_NETNS="dummy" + $env:CNI_IFNAME="dummy" + $env:CNI_PATH="c:\k\cni" #path to host-local.exe + + If(!(Test-Path c:/k/sourceVip.json)){ + Get-Content sourceVipRequest.json | .\cni\host-local.exe | Out-File sourceVip.json + } +} + +Export-ModuleMember DownloadFile +Export-ModuleMember CleanupOldNetwork +Export-ModuleMember IsNodeRegistered +Export-ModuleMember RegisterNode +Export-ModuleMember WaitForNetwork +Export-ModuleMember StartFlanneld +Export-ModuleMember GetSourceVip \ No newline at end of file