-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkind.sh
executable file
·68 lines (63 loc) · 1.75 KB
/
kind.sh
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
#!/usr/bin/env zsh
# inputs: create|delete
# used to create/destroy kind clusters
# puts kube contexts into ~/.kube/ or ~/.kube/kind/internal
# internal signifies in cluster access
function create_admin_cluster() {
cluster_name=$1
argocd=30001
vault=30003
kind create cluster --kubeconfig ~/.kube/${cluster_name} --config /dev/stdin <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: ${cluster_name}
networking:
apiServerPort: 30100
apiServerAddress: 0.0.0.0
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
# to check this configuration: kubectl -n kube-system get configmap kubeadm-config -oyaml
kind: ClusterConfiguration
apiServer:
certSANs:
- 0.0.0.0
- bwagner-studio
- localhost
extraPortMappings:
- containerPort: ${vault}
hostPort: ${vault}
protocol: TCP
- containerPort: ${argocd}
hostPort: ${argocd}
protocol: TCP
image: kindest/node:v1.28.0
EOF
}
function create_cluster() {
cluster_name=${1}
create_${cluster_name}_cluster ${cluster_name}
kind get kubeconfig --internal --name ${cluster_name} > ~/.kube/kind/internal/${cluster_name}
export KUBECONFIG=~/.kube/kind/internal/${cluster_name}
kubectl config view --raw --minify --flatten \
--output 'jsonpath={.clusters[].cluster.certificate-authority-data}' | base64 --decode \
> ${KUBECONFIG}_ca
kubectl config view --raw --minify --flatten \
--output 'jsonpath={.clusters[].cluster.server}' \
> ${KUBECONFIG}_server
}
function delete_cluster() {
cluster_name=${1}
kind delete clusters ${cluster_name}
rm \
~/.kube/${cluster_name} \
~/.kube/kind/internal/${cluster_name}
}
function create_dirs() {
mkdir -p ~/.kube/kind/internal
}
# main
action=${1}
create_dirs
${action}_cluster admin