-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathlnmp-k8s.ps1
143 lines (103 loc) · 2.63 KB
/
lnmp-k8s.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
<#
.SYNOPSIS
lnmp k8s CLI
.DESCRIPTION
lnmp k8s CLI
$ ./lnmp-k8s
.INPUTS
.OUTPUTS
.NOTES
#>
cd $PSScriptRoot
################################################################################
$KUBECTL_URL = "https://cdn.dl.k8s.io/release"
$KUBECTL_URL = "https://mirror.azure.cn/kubernetes/kubectl"
################################################################################
if (!(Test-Path .env.ps1 )) {
cp .env.example.ps1 .env.ps1
}
if (!(Test-Path .env )) {
cp .env.example .env
}
if (!(Test-Path coreos/.env )) {
cp coreos/.env.example coreos/.env
}
if (!(Test-Path wsl2/.env )) {
cp wsl2/.env.example wsl2/.env
}
if (!(Test-Path wsl2/.env.ps1 )) {
cp wsl2/.env.example.ps1 wsl2/.env.ps1
}
if (!(Test-Path systemd/.env )) {
cp systemd/.env.example systemd/.env
}
. "$PSScriptRoot/.env.example.ps1"
if (Test-Path .env.ps1 ) {
. "$PSScriptRoot/.env.ps1"
}
$k8s_current_context = kubectl config current-context
write-host "==> Kubernetes context is [ $k8s_current_context ]" -ForegroundColor Blue
Function print_info($message) {
write-host "==> $message"
}
Function print_help_info() {
echo "
Usage: lnmp-k8s.ps1 COMMAND
Commands:
kubectl-install Install kubectl
kubectl-info Get kubectl latest version info
wsl2 import wsl-k8s utils ps module
wsl [check|write-hosts|proxy]
"
}
if (!(Test-Path systemd/.env)) {
Copy-Item systemd/.env.example systemd/.env
}
if ($args.length -eq 0) {
print_help_info
exit
}
Function get_kubectl_version() {
$url = "https://cdn.dl.k8s.io/release/stable.txt"
$url = "https://mirror.azure.cn/kubernetes/kubectl/stable.txt"
return $KUBECTL_VERSION = $(curl.exe -fsSL $url)
}
$command, $others = $args
switch ($args[0]) {
"kubectl-install" {
$KUBECTL_VERSION = get_kubectl_version
write-host $KUBECTL_VERSION
$url = "${KUBECTL_URL}/${KUBECTL_VERSION}/bin/windows/amd64/kubectl.exe"
if (Test-Path C:\bin\kubectl.exe) {
print_info "kubectl already install"
return
}
curl.exe -fsSL $url -o C:\bin\kubectl.exe
}
"kubectl-info" {
$KUBECTL_VERSION = get_kubectl_version
"==> Latest Stable Version is: $KUBECTL_VERSION
"
}
wsl2 {
Import-Module $PSScriptRoot/wsl2/bin/WSL-K8S.psm1 -Force
Get-Command -Module WSL-K8S
}
wsl {
if($others -eq 'check'){
& $PSScriptRoot/wsl2/bin/kube-check.ps1
exit
}
if($others -eq 'write-hosts'){
& $PSScriptRoot/wsl2/bin/wsl2host.ps1 --write
exit
}
if($others -eq 'proxy'){
& $PSScriptRoot/wsl2/kube-wsl2windows.ps1 k8s
exit
}
}
Default {
Write-Warning "Command not found"
}
}