-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathcreate-kubeconfig.sh
More file actions
executable file
·40 lines (36 loc) · 980 Bytes
/
Copy pathcreate-kubeconfig.sh
File metadata and controls
executable file
·40 lines (36 loc) · 980 Bytes
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
#!/bin/bash
NAMESPACE="default"
SERVICE_ACCOUNT_NAME="kubevirt-vm-user"
KUBECONFIG_FILE="challenge/.kubeconfig"
function k() {
if command -v kubectl &> /dev/null; then
kubectl "$@"
elif command -v minikube &> /dev/null; then
minikube kubectl -- "$@"
else
echo "Error: Neither 'kubectl' nor 'minikube' could be found on your PATH."
return 1
fi
}
TOKEN=$(k get secret/$SERVICE_ACCOUNT_NAME-token -o jsonpath='{.data.token}' | base64 --decode)
CA_DATA=$(k get secret/$SERVICE_ACCOUNT_NAME-token -o jsonpath='{.data.ca\.crt}')
KUBE_API_SERVER=$(k config view --raw -o jsonpath='{.clusters[0].cluster.server}')
cat <<EOF > $KUBECONFIG_FILE
apiVersion: v1
kind: Config
clusters:
- cluster:
certificate-authority-data: $CA_DATA
server: $KUBE_API_SERVER
name: default
contexts:
- context:
cluster: default
user: $SERVICE_ACCOUNT_NAME
name: default
current-context: default
users:
- name: $SERVICE_ACCOUNT_NAME
user:
token: $TOKEN
EOF