2658f4f2 by Adam Heath

Initial framework for starting k3d clusters.

1 parent 601c5e45
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.
1 #!/bin/sh
2
3 APP_DIR="$(cd "$(dirname "$0")/."; pwd -P)"
4
5 exec "$APP_DIR/k3d-allocator/start-k3d.sh" --app-dir "$APP_DIR" "$@"
6
1 ---
2 apiVersion: k3d.io/v1alpha5
3 kind: Simple
4 metadata:
5 name: local
6 ports:
7 - port: 80:80
8 nodeFilters:
9 - loadbalancer
10 - port: 443:443
11 nodeFilters:
12 - loadbalancer
13
14 options:
15 k3s:
16 extraArgs:
17 - arg: "--disable=traefik"
18 nodeFilters:
19 - servers:*
1 # Copy this to .k3d.env, adjust as needed
2
3 BUILD_NAME=um-local-adam
4
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