Initial framework for starting k3d clusters.
Showing
5 changed files
with
95 additions
and
0 deletions
README.md
0 → 100644
1 | * Create a new repo, add this as a submodule(generally placed as | ||
2 | k3d-allocator). | ||
3 | * Copy examples/k3d.env.sample to $repo/.k3d.env, configure BUILD_NAME, | ||
4 | add to .gitignore. | ||
5 | * Copy examples/app-start-k3d.sh to $repo/start-k3d.sh, adjust | ||
6 | relative path to k3d-allocator/start-k3d.sh, add to git. | ||
7 | * Copy examples/k3d.conf.sample to $repo/k3d.conf, adjust if needed, | ||
8 | add to git. |
examples/app-start-k3d.sh
0 → 100755
examples/k3d.conf.sample
0 → 100644
examples/k3d.env.sample
0 → 100644
start-k3d.sh
0 → 100755
1 | #!/bin/bash | ||
2 | |||
3 | set -xe | ||
4 | |||
5 | APP_DIR="" | ||
6 | BUILD_NAME="" | ||
7 | while [[ $# -gt 0 ]]; do | ||
8 | case "$1" in | ||
9 | (--app-dir) | ||
10 | APP_DIR="$2" | ||
11 | shift 2 | ||
12 | ;; | ||
13 | (--build-name) | ||
14 | BUILD_NAME="$2" | ||
15 | shift 2 | ||
16 | ;; | ||
17 | (*) | ||
18 | break | ||
19 | esac | ||
20 | done | ||
21 | |||
22 | if [[ -f $APP_DIR/.k3d.env ]]; then | ||
23 | . $APP_DIR/.k3d.env | ||
24 | fi | ||
25 | |||
26 | [[ $APP_DIR ]] || { echo "Please pass --app-dir!" 1>&2; exit 1; } | ||
27 | [[ $BUILD_NAME ]] || { echo "Please configure --build-name!" 1>&2; exit 1; } | ||
28 | [[ -f $APP_DIR/k3d.conf ]] || { echo "No k3d.conf found in $APP_DIR!" 1>&2; exit 1; } | ||
29 | |||
30 | if ! k3d cluster list "${BUILD_NAME}" 1>/dev/null 2>/dev/null; then | ||
31 | k3d cluster create -c "$APP_DIR/k3d.conf" "${BUILD_NAME}" | ||
32 | fi | ||
33 | k3d kubeconfig merge "${BUILD_NAME}" --kubeconfig-merge-default --kubeconfig-switch-context | ||
34 | |||
35 | generate_coredns_custom() { | ||
36 | search_domains="$(sed -n -e 's/^search //p' /etc/resolv.conf | tr ' ' '\n' | sed -e 's/\.$//')" | ||
37 | nameserver_address="$(sed -n -e 's/^nameserver *//p' /etc/resolv.conf | head -n 1)" | ||
38 | cat << _EOF_ | ||
39 | apiVersion: v1 | ||
40 | kind: ConfigMap | ||
41 | metadata: | ||
42 | name: coredns-custom | ||
43 | namespace: kube-system | ||
44 | data: | ||
45 | _EOF_ | ||
46 | for search_domain in $search_domains; do | ||
47 | cat << _EOF_ | ||
48 | ${search_domain}.server: | | ||
49 | ${search_domain}{ | ||
50 | forward . ${nameserver_address} | ||
51 | } | ||
52 | _EOF_ | ||
53 | done | ||
54 | } | ||
55 | |||
56 | generate_coredns_custom | kubectl apply -f - | ||
57 | kubectl rollout restart deployment -n kube-system coredns | ||
58 |
-
Please register or sign in to post a comment