1
0
Fork 0
home-stack-kustomize/setup-dev-cluster.sh

79 lines
2.3 KiB
Bash
Executable File

#!/bin/bash -ex
cluster_name='local'
k3s_registry_config="$HOME/.config/k3d/registries.yaml"
# generate manifest to be deployed on boot
# make cluster
# auto_deploy_manifest="$(dirname "$(readlink -f "$0")")/build/dev/cluster.yaml"
# cluster registry configuration
if [[ ! -f "$k3s_registry_cofing" ]]; then
mkdir -p "$(dirname "$k3s_registry_config")"
cat >"$k3s_registry_config" <<EOF
mirrors:
"registry-localhost:5000":
endpoint:
- http://registry-localhost:5000
EOF
else
echo '~/.config/k3d/registries.yaml already exists, skipping generation'
fi
# local k3s cluster
if ! k3d cluster list "$cluster_name" &>/dev/null; then
k3d cluster create "$cluster_name" \
--servers 1 \
--agents 3 \
--volume "$k3s_registry_config:/etc/rancher/k3s/registries.yaml" \
-p 80:80@loadbalancer \
-p 443:443@loadbalancer
sleep 10
fi
# --volume ":/var/lib/rancher/k3s/server/manifests/cluster.yaml" \
# local docker registry
if ! docker ps -a | grep registry-localhost &>/dev/null; then
docker volume create local_registry
docker run -d \
--name registry-localhost \
--net "k3d-$cluster_name" \
--volume local_registry:/var/lib/registry \
--restart always \
-p 5000:5000 \
registry:2
fi
# local nfs server
# if ! docker ps -a | grep nfs-localhost &>/dev/null; then
# docker volume create local_nfs
# docker run -d \
# --name nfs-localhost \
# --net "k3d-$cluster_name" \
# --ip 172.31.0.10 \
# --volume "$PWD/.nfs/nextcould:/data/nextcloud" \
# --volume /lib/modules:/lib/modules:ro \
# --restart always \
# --cap-add SYS_ADMIN \
# --cap-add SYS_MODULE \
# --env NFS_EXPORT_0='/data *(rw,sync,insecure,no_subtree_check,no_root_squash,fsid=0)' \
# --env NFS_LOG_LEVEL=DEBUG \
# -p 2049:2049 \
# erichough/nfs-server:2.2.1
# sleep 10
# fi
# sudo modprobe netfs
# sudo modprobe fscache
# sudo modprobe sunrpc
# sudo modprobe grace
# sudo modprobe lockd
# sudo modprobe nfs
# sudo modprobe nfs_acl
# sudo modprobe auth_rpcgss
# sudo modprobe nfsd
# k3d kubeconfig merge "$cluster_name" --switch-context >/dev/null
# kubectl apply -f "$auto_deploy_manifest"
kubectl config use-context "k3d-$cluster_name"
kubectl get nodes