-
Notifications
You must be signed in to change notification settings - Fork 0
/
kind-actions.sh
187 lines (162 loc) · 4.43 KB
/
kind-actions.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
function _prepare_kind_cluster_config() {
file=${1:-"/tmp/cluster.yaml"}
echo $file
cat >$file <<EOL
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
ipFamily: dual
apiServerAddress: "127.0.0.1"
nodes:
- role: control-plane
EOL
}
function _prepare_kind_cluster_config_2() {
local file=${1:-"/tmp/cluster.yaml"}
echo $file
cat >$file <<EOL
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
ipFamily: dual
apiServerAddress: "127.0.0.1"
nodes:
- role: control-plane
- role: worker
- role: worker
EOL
}
function _prepare_kind_cluster_config_3() {
local file=${1:-"/tmp/cluster.yaml"}
echo $file
cat >$file <<EOL
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
ipFamily: dual
apiServerAddress: "127.0.0.1"
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker
EOL
}
function kind-create-1.16.5() {
local name=${1:-"k-1-16-5"}
_prepare_kind_cluster_config /tmp/cluster.yaml
kind create cluster --config /tmp/cluster.yaml --name $name --image=kindest/node:v1.16.15
}
function kind-create-1.19.11() {
local name=${1:-"k-1-19-11"}
_prepare_kind_cluster_config /tmp/cluster.yaml
kind create cluster --config /tmp/cluster.yaml --name $name --image=kindest/node:v1.19.11
}
function kind-create-1.21.1() {
local name=${1:-"k-1-21-1"}
_prepare_kind_cluster_config /tmp/cluster.yaml
kind create cluster --config /tmp/cluster.yaml --name $name --image=kindest/node:v1.21.1
}
function kind-create-1.24.3-ipv6() {
local name=${1:-"k-1-24-3"}
local node=$2
if [ -z "$node" ]; then
_prepare_kind_cluster_config /tmp/cluster.yaml
else
_prepare_kind_cluster_config_3 /tmp/cluster.yaml
fi
kind create cluster --config /tmp/cluster.yaml --name $name --image=kindest/node:v1.24.3
}
function kind-create-1.24.3() {
local name=${1:-"k-1-24-3"}
local node=$2
if [ -z "$node" ]; then
_prepare_kind_cluster_config /tmp/cluster.yaml
else
_prepare_kind_cluster_config_3 /tmp/cluster.yaml
fi
kind create cluster --config /tmp/cluster.yaml --name $name --image=kindest/node:v1.24.3
}
function kind-create-1.27.3() {
local name=${1:-"k-1-27-3"}
local node=$2
if [ -z "$node" ]; then
_prepare_kind_cluster_config /tmp/cluster.yaml
else
_prepare_kind_cluster_config_3 /tmp/cluster.yaml
fi
kind create cluster --config /tmp/cluster.yaml --name $name --image=kindest/node:v1.27.3
}
function kind-create-1.28.0() {
local name=${1:-"k-1-28-0"}
local node=$2
if [ -z "$node" ]; then
_prepare_kind_cluster_config /tmp/cluster.yaml
else
_prepare_kind_cluster_config_3 /tmp/cluster.yaml
fi
kind create cluster --config /tmp/cluster.yaml --name $name --image=kindest/node:v1.28.0
}
function default-cluster-config() {
p=/${RANDOM:0:2}
}
function kind-delete() {
kind delete cluster --name $(kind get clusters | fzf --prompt="select cluster you want to delete")
}
function kind-list() {
kind get clusters
}
function kind-delete-all() {
kind get clusters | xargs -I{} kind delete cluster --name {}
}
function kind-list-image() {
# category: glasses
dockerhub-list-tags kindest/node
}
function kind-load-image-in-current() {
local cluster=$(cat ~/.kube/kind.current)
local image=$1
kind load docker-image $image --name $cluster
}
function kind-pull-andload-image-in-current() {
local cluster=$(cat ~/.kube/kind.current)
local image=$1
docker pull $image
kind load docker-image $image --name $cluster
}
function kind-load-image() {
# @arg-len: 2
# @fzf-backup
local image=$1
local cluster=$2
if [ -z "$cluster" ]; then
cluster=$(kind get clusters | fzf)
fi
# docker pull $image
kind load docker-image $image --name $cluster
}
function kind-source-kubeconfig() {
# @arg-len: 1
# @fzf
local cluster=$1
if [ -z "$cluster" ]; then
cluster=$(kind get clusters | fzf)
fi
kind get kubeconfig --name=$cluster >~/.kube/$cluster
echo "$cluster" >~/.kube/kind.current
local ip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $cluster-control-plane)
echo $cluster $ip
export KUBECONFIG=~/.kube/$cluster
cat $KUBECONFIG | grep server
sed -i "s|server.*|server: https://$ip:6443|g" ~/.kube/$cluster
echo $KUBECONFIG
}
# 将kind的kubectl设置为默认的config ~/.kube/config
function kind-default-kubeconfig() {
local cluster=$1
if [ -z "$cluster" ]; then
cluster=$(kind get clusters | fzf)
fi
kind-source-kubeconfig $cluster
cp ~/.kube/$cluster ~/.kube/config
}