2658f4f2 by Adam Heath

Initial framework for starting k3d clusters.

1 parent 601c5e45
* Create a new repo, add this as a submodule(generally placed as
k3d-allocator).
* Copy examples/k3d.env.sample to $repo/.k3d.env, configure BUILD_NAME,
add to .gitignore.
* Copy examples/app-start-k3d.sh to $repo/start-k3d.sh, adjust
relative path to k3d-allocator/start-k3d.sh, add to git.
* Copy examples/k3d.conf.sample to $repo/k3d.conf, adjust if needed,
add to git.
#!/bin/sh
APP_DIR="$(cd "$(dirname "$0")/."; pwd -P)"
exec "$APP_DIR/k3d-allocator/start-k3d.sh" --app-dir "$APP_DIR" "$@"
---
apiVersion: k3d.io/v1alpha5
kind: Simple
metadata:
name: local
ports:
- port: 80:80
nodeFilters:
- loadbalancer
- port: 443:443
nodeFilters:
- loadbalancer
options:
k3s:
extraArgs:
- arg: "--disable=traefik"
nodeFilters:
- servers:*
# Copy this to .k3d.env, adjust as needed
BUILD_NAME=um-local-adam
#!/bin/bash
set -xe
APP_DIR=""
BUILD_NAME=""
while [[ $# -gt 0 ]]; do
case "$1" in
(--app-dir)
APP_DIR="$2"
shift 2
;;
(--build-name)
BUILD_NAME="$2"
shift 2
;;
(*)
break
esac
done
if [[ -f $APP_DIR/.k3d.env ]]; then
. $APP_DIR/.k3d.env
fi
[[ $APP_DIR ]] || { echo "Please pass --app-dir!" 1>&2; exit 1; }
[[ $BUILD_NAME ]] || { echo "Please configure --build-name!" 1>&2; exit 1; }
[[ -f $APP_DIR/k3d.conf ]] || { echo "No k3d.conf found in $APP_DIR!" 1>&2; exit 1; }
if ! k3d cluster list "${BUILD_NAME}" 1>/dev/null 2>/dev/null; then
k3d cluster create -c "$APP_DIR/k3d.conf" "${BUILD_NAME}"
fi
k3d kubeconfig merge "${BUILD_NAME}" --kubeconfig-merge-default --kubeconfig-switch-context
generate_coredns_custom() {
search_domains="$(sed -n -e 's/^search //p' /etc/resolv.conf | tr ' ' '\n' | sed -e 's/\.$//')"
nameserver_address="$(sed -n -e 's/^nameserver *//p' /etc/resolv.conf | head -n 1)"
cat << _EOF_
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
_EOF_
for search_domain in $search_domains; do
cat << _EOF_
${search_domain}.server: |
${search_domain}{
forward . ${nameserver_address}
}
_EOF_
done
}
generate_coredns_custom | kubectl apply -f -
kubectl rollout restart deployment -n kube-system coredns