-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure-windows.ps1
149 lines (114 loc) · 5.05 KB
/
configure-windows.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<#
.SYNOPSIS
Configures windows worker node
.LINK
https://github.com/bsteciuk/k8s-ovn-windows-cluster
https://kubernetes.io/docs/getting-started-guides/windows/
.EXAMPLE
.\configure-windows.ps1 -networkInterfaceAlias "Ethernet 2"
.FUNCTIONALITY
Not sure How to specify or use
Does not appear in basic, -full, or -detailed
Should appear with -functionality
.PARAMETER networkInterfaceAlias
The network interface name that is provisioned for the cluster , what
comes back from ipconfig for the "external" interface where this node is accessible
, e.g. "Ethernet 2"
.PARAMETER vagrant
Specifies whether this script is running in the context of vagrant, defaults to $false
.PARAMETER masterIp
The IP address of the master node.
.PARAMETER clusterSubnet
The subnet from which nodes are assigned subnets from for pod addresses.
.PARAMETER serviceClusterIpRange
The subnet to be used by kubernetes services
#>
param (
[Parameter(Mandatory=$true)][string]$networkInterfaceAlias,
[Parameter(Mandatory=$false)][switch]$vagrant = $false,
[Parameter(Mandatory=$false)][string]$masterIp = "172.20.2.30",
[Parameter(Mandatory=$false)][string]$clusterSubnet = "192.168.0.0/16",
[Parameter(Mandatory=$false)][string]$serviceClusterIpRange = "172.16.1.0/24"
)
#Only run this if vagrant
if ($vagrant) {
Set-Location -Path "C:\k"
.\kubelet-service.exe install
$joinCommand = "C:\k\$(Get-Content C:\vagrant\join.sh -Raw)"
Invoke-Expression $joinCommand
start-service kubelet
}
[int]$retryCount = 0;
[bool]$success = $false
$command = { $( C:\k\kubectl.exe describe node $( hostname ).ToLower() | Select-String ovn_host_subnet ).Line.Split("{=}")[1] }
Do {
try
{
$ovnHostSubnet=Invoke-Command -ScriptBlock $command -ErrorAction Stop
$success = $true
} catch {
Write-Host "Node info not yet available from apiserver... sleeping 15s."
$retryCount++
Sleep 15
}
} Until($retryCount -eq 6 -or $success)
if( ! $success ){
Write-Host "Could not retrieve node info from apiserver"
exit 1
}
echo "ovnHostSubnet: $ovnHostSubnet"
$gatewayIp="$($ovnHostSubnet -replace "(\d{1,3}\.\d{1,3}.\d{1,3}\.).*", '$1')1"
echo "gatewayIp: $gatewayIp"
$ipAddress = (Get-NetIPConfiguration | where {$_.InterfaceAlias -eq $networkInterfaceAlias }).ipv4address.ipaddress
Write-Host "ipAddress: $ipAddress"
[int]$retryCount = 0;
[bool]$success = $false
$command = { $( C:\k\kubectl.exe describe node $( hostname ).ToLower() | Select-String ovn_host_subnet ).Line.Split("{=}")[1] }
Do {
try
{
$ovnHostSubnet=Invoke-Command -ScriptBlock $command -ErrorAction Stop
$success = $true
} catch {
Write-Host "Node info not yet available from apiserver... sleeping 15s."
$retryCount++
Sleep 15
}
} Until($retryCount -eq 6 -or $success)
if( ! $success ){
Write-Host "Could not retrieve node info from apiserver"
exit 1
}
echo "ovnHostSubnet: $ovnHostSubnet"
$gatewayIp="$($ovnHostSubnet -replace "(\d{1,3}\.\d{1,3}.\d{1,3}\.).*", '$1')1"
echo "gatewayIp: $gatewayIp"
$ipAddress = (Get-NetIPConfiguration | where {$_.InterfaceAlias -eq $networkInterfaceAlias }).ipv4address.ipaddress
Write-Host "ipAddress: $ipAddress"
docker network create -d transparent --gateway $gatewayIp --subnet $ovnHostSubnet -o com.docker.network.windowsshim.interface="$networkInterfaceAlias" external
sleep 2;
$a = Get-NetAdapter | where Name -Match HNSTransparent
Rename-NetAdapter $a[0].Name -NewName HNSTransparent
Stop-Service ovs-vswitchd -force; Disable-VMSwitchExtension "Cloudbase Open vSwitch Extension";
ovs-vsctl --no-wait del-br br-ex
ovs-vsctl --no-wait --may-exist add-br br-ex
ovs-vsctl --no-wait add-port br-ex HNSTransparent -- set interface HNSTransparent type=internal
ovs-vsctl --no-wait add-port br-ex "$networkInterfaceAlias"
Get-VMSwitch -SwitchType External | Enable-VMSwitchExtension "Cloudbase Open vSwitch Extension"; sleep 2; Restart-Service ovs-vswitchd
$GUID = (New-Guid).Guid
ovs-vsctl set Open_vSwitch . external_ids:system-id="$($GUID)"
Start-BitsTransfer https://raw.githubusercontent.com/bsteciuk/k8s-ovn-windows-cluster/master/ovn_k8s.conf-windows -Destination "$env:OVS_SYSCONFDIR"
Add-Content C:\Windows\System32\drivers\etc\hosts "`r`n$ipAddress $(hostname)"
if ($vagrant) {
C:\cni\ovnkube.exe -k8s-apiserver "https://$masterIp`:6443" `
-k8s-cacert "C:\etc\kubernetes\pki\ca.crt" `
-init-node "$($(hostname).ToLower())" `
-k8s-token "$(Get-Content C:\vagrant\token)" `
-nb-address "tcp://$masterIp`:6641" `
-sb-address "tcp://$masterIp`:6642" `
-cluster-subnet "$clusterSubnet" `
-cni-conf-dir "C:\cni-conf" `
-service-cluster-ip-range "$serviceClusterIpRange"
Write-Host "ovs-vsctl set Open_vSwitch . external_ids:ovn-encap-ip=$ipAddress"
ovs-vsctl set Open_vSwitch . external_ids:ovn-encap-ip="$ipAddress"
}
Start-BitsTransfer https://raw.githubusercontent.com/bsteciuk/k8s-ovn-windows-cluster/master/ovn_k8s.conf-windows -Destination "$env:OVS_SYSCONFDIR/ovn_k8s.conf"