This repository was archived by the owner on Mar 21, 2022. It is now read-only.
forked from canonical/microk8s
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdashboard-proxy.py
80 lines (69 loc) · 1.98 KB
/
dashboard-proxy.py
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
#!/usr/bin/python3
from subprocess import check_output
def dashboard_proxy():
print("Checking if Dashboard is running.")
command = ["/snap/microk8s/current/microk8s-enable.wrapper", "dashboard"]
output = check_output(command)
if b"Addon dashboard is already enabled." not in output:
print("Waiting for Dashboard to come up.")
command = [
"microk8s.kubectl",
"-n",
"kube-system",
"wait",
"--timeout=240s",
"deployment",
"kubernetes-dashboard",
"--for",
"condition=available",
]
check_output(command)
command = [
"/snap/microk8s/current/microk8s-kubectl.wrapper",
"-n",
"kube-system",
"get",
"secret",
]
output = check_output(command)
secret_name = None
for line in output.split(b"\n"):
if line.startswith(b"default-token"):
secret_name = line.split()[0].decode()
break
if not secret_name:
print("Cannot find the dashboard secret.")
command = [
"/snap/microk8s/current/microk8s-kubectl.wrapper",
"-n",
"kube-system",
"describe",
"secret",
secret_name,
]
output = check_output(command)
token = None
for line in output.split(b"\n"):
if line.startswith(b"token:"):
token = line.split()[1].decode()
if not token:
print("Cannot find token from secret.")
print("Dashboard will be available at https://127.0.0.1:10443")
print("Use the following token to login:")
print(token)
command = [
"/snap/microk8s/current/microk8s-kubectl.wrapper",
"port-forward",
"-n",
"kube-system",
"service/kubernetes-dashboard",
"10443:443",
"--address",
"0.0.0.0",
]
try:
check_output(command)
except KeyboardInterrupt:
exit(0)
if __name__ == "__main__":
dashboard_proxy()