Repository navigation
Expand file tree
/
Copy pathjoin-rke2-win-agent.ps1
More file actions
106 lines (94 loc) · 3.05 KB
/
Copy pathjoin-rke2-win-agent.ps1
File metadata and controls
106 lines (94 loc) · 3.05 KB
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
<#
.SYNOPSIS
Setup and Install Rancher RKE2 in Windows Worker Nodes.
.DESCRIPTION
Run the script to setup and install all Rancher RKE2 related needs.
.Parameter ServerIP
Server IP of Primary server where rke2 is already installed and the worker will join.`
.Parameter Token
Token of Primary server.`
.Parameter PublicIP
Public IP of Agent server.`
.Parameter Version
Version of rke2 to download from github.`
.Parameter Commit
Commit of RKE2 to download from temporary cloud storage.
If set, this forces Method=tar.
* (for developer & QA use only)`
.EXAMPLE
Usage:
Invoke-WebRequest ((New-Object System.Net.WebClient).DownloadString('https://github.com/rancher/rke2/blob/master/setup-and-install.ps1'))
./setup-and-install.ps1
#>
[CmdletBinding()]
param (
[Parameter()]
[String]
$ServerIP,
[Parameter()]
[String]
$Token,
[Parameter()]
[String]
$Version,
[Parameter()]
[String]
$Commit
)
function Write-InfoLog() {
Write-Output "[INFO] $($args -join " ")"
}
function Write-WarnLog() {
Write-Output "[WARN] $($args -join " ")"
}
function Write-DebugLog() {
Write-Output "[DEBUG] $($args -join " ")"
}
# Set the version or commit based of cli
function Set-Version() {
if ($Commit) {
$Version = "commit $($Commit)"
}
elseif ($Version) {
$Version = $Version
}
return $Version
}
function Enable-Features() {
Enable-WindowsOptionalFeature -Online -FeatureName Containers -All
Restart-Computer -Wait -For PowerShell -Timeout 300 -Delay 2
}
function Setup-Config(){
Write-InfoLog "Creating rke2 directory..."
New-Item -Type Directory c:/etc/rancher/rke2 -Force
Write-InfoLog "Fetch public IP..."
$publicIP = (Invoke-WebRequest -uri "https://api.ipify.org/").Content.Trim()
Write-InfoLog "Setting up rke2 config.yaml file..."
Set-Content -Path c:/etc/rancher/rke2/config.yaml -Value "server: https://$($ServerIP):9345`ntoken: $Token`nnode-external-ip: $publicIP`n"
Get-Content -Path c:/etc/rancher/rke2/config.yaml
}
function Setup-EnvironmentVariables(){
Write-InfoLog "Setting up environment vars..."
[System.Environment]::SetEnvironmentVariable(
"Path",[System.Environment]::GetEnvironmentVariable(
"Path", [System.EnvironmentVariableTarget]::Machine) + ";c:\var\lib\rancher\rke2\bin;c:\usr\local\bin",
[System.EnvironmentVariableTarget]::Machine)
}
function Install-rke2(){
Write-InfoLog "Downloading install script..."
Invoke-WebRequest -Uri https://raw.githubusercontent.com/rancher/rke2/master/install.ps1 -Outfile C:\Users\Administrator\install.ps1
Write-InfoLog "Installing rke2 $Version..."
Invoke-Expression -Command "C:\Users\Administrator\install.ps1 -Version $Version"
}
function Start-rke2(){
Write-InfoLog "Adding rke2-agent service..."
Invoke-Expression -Command "C:\usr\local\bin\rke2.exe agent service --add"
Write-InfoLog "Starting rke2-agent service..."
Start-Service rke2
}
Enable-Features
Setup-Config
Setup-EnvironmentVariables
Set-Version
Install-rke2
Start-rke2