forked from janviudapi/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall-KubeCTL.ps1
57 lines (53 loc) · 2.16 KB
/
Install-KubeCTL.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
<#
.NOTES
--------------------------------------------------------------------------------
Code generated by: Visual Studio Code
Created on: 01/17/2021 4:57 AM
Generated by: http://vcloud-lab.com
Written by: J U
Tested on: Windows 10, PowerShell 5.1
--------------------------------------------------------------------------------
.DESCRIPTION
GUI script generated using Visual Studio Code
#>
#Install Kubernetes on Windows
[CmdletBinding()]
param (
[Parameter(
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage='Type folder path to download kubectl.exe'
)]
[Alias('Folder')]
[string]$Path = 'C:\Kubernetes' #change here
)
$kubectlPath = $Path
if (-not(Test-Path $kubectlPath))
{
Write-Host "`t-- New directory $kubectlPath created."
$parent = Split-Path $kubectlPath -parent
$leaf = Split-Path $kubectlPath -leaf
New-Item -Name $leaf -Path $parent -ItemType Directory | Out-Null
}
else {
Write-Host "`t-- directory $kubectlPath already exists."
}
if (-not(Test-Path "$kubectlPath\kubectl.exe"))
{
Write-Host "`t-- Downloading latest version kubectl.exe to directory $kubectlPath."
$latestVersion = Invoke-RestMethod -Uri 'https://storage.googleapis.com/kubernetes-release/release/stable.txt'
Invoke-WebRequest -Uri "https://storage.googleapis.com/kubernetes-release/release/$latestVersion/bin/windows/amd64/kubectl.exe" -OutFile "$kubectlPath\kubectl.exe"
}
else {
Write-Host "`t-- kubectl.exe already exists under directory $kubectlPath."
}
$pathList = [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::User) -split ';'
if (-not($pathList -contains $kubectlPath))
{
Write-Host "`t-- Setting up Environment variable 'path' - $kubectlPath."
[System.Environment]::SetEnvironmentVariable('Path', "$([System.Environment]::GetEnvironmentVariable('Path'));$kubectlPath", [System.EnvironmentVariableTarget]::User)
}
else {
Write-Host "`t-- Environment variable 'path' - $kubectlPath already exists."
}