-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubeconfig.yml.ts
43 lines (39 loc) · 1.36 KB
/
kubeconfig.yml.ts
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
import { apiserverPublicIp, apiserverPort, domainName } from "./helpers.ts";
import * as util from "node:util";
import * as childProcess from "node:child_process";
import { encodeBase64 } from "jsr:@std/encoding/base64";
const exec = util.promisify(childProcess.exec);
const yaml = String.raw;
const sh = String.raw;
const [ca, clientCert, clientKey] = await Promise.all(
[
exec(sh`ssh root@${apiserverPublicIp} -i ${domainName}-private.key -- "cat /etc/kubernetes/ssl/ca.crt"`),
exec(sh`ssh root@${apiserverPublicIp} -i ${domainName}-private.key -- "cat /etc/kubernetes/ssl/apiserver-kubelet-client.crt"`),
exec(sh`ssh root@${apiserverPublicIp} -i ${domainName}-private.key -- "cat /etc/kubernetes/ssl/apiserver-kubelet-client.key"`),
]
)
.then((res) => res.map(({ stdout }) => encodeBase64(stdout)))
.catch(() => {
console.warn("Regenerate kubeconfig after kubernetes cluster is up and running");
return ['', '', ''];
});
export default yaml`
apiVersion: v1
kind: Config
clusters:
- cluster:
certificate-authority-data: ${ca}
server: https://${apiserverPublicIp}:${apiserverPort}
name: ${domainName}
contexts:
- context:
cluster: ${domainName}
user: admin
name: admin@${domainName}
current-context: admin@${domainName}
users:
- name: admin
user:
client-certificate-data: ${clientCert}
client-key-data: ${clientKey}
`;