-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkind.sh
executable file
·143 lines (121 loc) · 4.24 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
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
#!/bin/sh
#
# Helper script to start KinD
#
# Also adds a docker-registry and an ingress to aid local development
#
# See https://kind.sigs.k8s.io/docs/user/quick-start/
#
set -o errexit
[ "$TRACE" ] && set -x
VERBOSE=1
[ "$TRACE" ] && VERBOSE=3
#KIND_K8S_IMAGE=${KIND_K8S_IMAGE:-"kindest/node:v1.20.15@sha256:6f2d011dffe182bad80b85f6c00e8ca9d86b5b8922cdf433d53575c4c5212248"}
KIND_K8S_IMAGE=${KIND_K8S_IMAGE:-"kindest/node:v1.21.12@sha256:f316b33dd88f8196379f38feb80545ef3ed44d9197dca1bfd48bcb1583210207"}
#KIND_K8S_IMAGE=${KIND_K8S_IMAGE:-"kindest/node:v1.22.9@sha256:8135260b959dfe320206eb36b3aeda9cffcb262f4b44cda6b33f7bb73f453105"}
KIND_CLUSTER_NAME=${KIND_CLUSTER_NAME:-"istio"}
KIND_DOCKER_REGISTRY_NAME=${KIND_DOCKER_REGISTRY_NAME:-"kind-docker-registry"}
KIND_DOCKER_REGISTRY_PORT=${KIND_DOCKER_REGISTRY_PORT:-5000}
KIND_DOCKER_HOST_ALIAS=${KIND_DOCKER_HOST_ALIAS:-"docker"}
KIND_FIX_KUBECONFIG="${KIND_FIX_KUBECONFIG:-"false"}"
KIND_NGINX_INGRESS_VERSION=${KIND_NGINX_INGRESS_VERSION:-"master"}
KIND_INSTALL_DOCKER_REGISTRY=${KIND_INSTALL_DOCKER_REGISTRY:-"0"}
KIND_WAIT=${KIND_WAIT:-"120s"}
KIND_API_SERVER_ADDRESS=${KIND_API_SERVER_ADDRESS:-"0.0.0.0"}
KIND_API_SERVER_PORT=${KIND_API_SERVER_PORT:-6443}
KIND_INSTALL_DOCKER_REGISTRY=${KIND_INSTALL_DOCKER_REGISTRY:-0}
KIND_INSTALL_NGINX_INGRESS=${KIND_INSTALL_DOCKER_REGISTRY:-0}
if [[ "x${ENV}" != "x" ]]; then
source ./env-${ENV}.sh
else
source ./env-default.sh
fi
docker_registry_start() {
running="$(docker inspect -f '{{.State.Running}}' "${KIND_DOCKER_REGISTRY_NAME}" 2>/dev/null || true)"
if [ "${running}" != 'true' ]; then
docker run \
-d --restart=always -p "${KIND_DOCKER_REGISTRY_PORT}:5000" --name "${KIND_DOCKER_REGISTRY_NAME}" \
registry:2
fi
docker network connect "${KIND_CLUSTER_NAME}" "${KIND_DOCKER_REGISTRY_NAME}" || true
}
## Create a cluster with the local registry enabled in container
create() {
cat <<EOF | kind create -v ${VERBOSE} cluster --name="${KIND_CLUSTER_NAME}" --image="${KIND_K8S_IMAGE}" --wait="${KIND_WAIT}" --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
apiServerAddress: ${KIND_API_SERVER_ADDRESS}
apiServerPort: ${KIND_API_SERVER_PORT}
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${KIND_DOCKER_REGISTRY_PORT}"]
endpoint = ["http://${KIND_DOCKER_REGISTRY_NAME}:${KIND_DOCKER_REGISTRY_PORT}"]
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
- |
kind: ClusterConfiguration
networking:
dnsDomain: ${CLUSTER_DNS_DOMAIN}
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
- role: worker
EOF
if [ "$KIND_FIX_KUBECONFIG" = "true" ]; then
sed -i -e "s/server: https:\/\/0\.0\.0\.0/server: https:\/\/$KIND_DOCKER_HOST_ALIAS/" "${HOME}/.kube/config"
fi
# https://docs.tilt.dev/choosing_clusters.html#discovering-the-registry
for node in $(kind get nodes --name "${KIND_CLUSTER_NAME}"); do
kubectl annotate node "${node}" "kind.x-k8s.io/registry=localhost:${KIND_DOCKER_REGISTRY_PORT}";
done
# Add nginx ingress
if [ "${KIND_INSTALL_NGINX_INGRESS}" = '1' ]; then
kubectl apply -f "https://raw.githubusercontent.com/kubernetes/ingress-nginx/${KIND_NGINX_INGRESS_VERSION}/deploy/static/provider/kind/deploy.yaml"
kubectl wait --namespace ingress-nginx \
--for=condition=available \
--timeout=90s \
deploy/ingress-nginx-controller
fi
if [ "${KIND_INSTALL_DOCKER_REGISTRY}" = '1' ]; then
docker_registry_start
fi
}
## Delete the cluster
delete() {
kind delete cluster --name "${KIND_CLUSTER_NAME}"
}
## Display usage
usage()
{
echo "usage: $0 [create|delete]"
}
## Argument parsing
if [ "$#" = "0" ]; then
usage
exit 1
fi
while [ "$1" != "" ]; do
case $1 in
create ) create
;;
delete ) delete
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done