2020-08-29 04:54:40 +00:00
|
|
|
#!/bin/bash -ex
|
2020-08-02 03:14:58 +00:00
|
|
|
|
|
|
|
cluster_name='local'
|
|
|
|
k3s_registry_config="$HOME/.config/k3d/registries.yaml"
|
|
|
|
|
|
|
|
# generate manifest to be deployed on boot
|
|
|
|
make auto-deploy
|
|
|
|
auto_deploy_manifest="$(dirname "$(readlink -f "$0")")/build/dev/auto-deploy.yaml"
|
|
|
|
|
|
|
|
# cluster registry configuration
|
|
|
|
if [[ ! -f "$k3s_registry_cofing" ]]; then
|
|
|
|
mkdir -p "$(dirname "$k3s_registry_config")"
|
|
|
|
cat >"$k3s_registry_config" <<EOF
|
|
|
|
mirrors:
|
2020-08-29 04:54:40 +00:00
|
|
|
"registry-localhost:5000":
|
2020-08-02 03:14:58 +00:00
|
|
|
endpoint:
|
2020-08-29 04:54:40 +00:00
|
|
|
- http://registry-localhost:5000
|
2020-08-02 03:14:58 +00:00
|
|
|
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 \
|
|
|
|
--k3s-server-arg '--no-deploy=traefik' \
|
|
|
|
--volume "$k3s_registry_config:/etc/rancher/k3s/registries.yaml" \
|
2020-08-11 04:37:20 +00:00
|
|
|
-p 80:80@loadbalancer \
|
|
|
|
-p 443:443@loadbalancer
|
|
|
|
sleep 10
|
2020-08-02 03:14:58 +00:00
|
|
|
fi
|
|
|
|
# --volume ":/var/lib/rancher/k3s/server/manifests/auto-deploy.yaml" \
|
|
|
|
|
|
|
|
# local docker registry
|
2020-08-29 04:54:40 +00:00
|
|
|
if ! docker ps -a | grep registry-localhost &>/dev/null; then
|
2020-08-02 03:14:58 +00:00
|
|
|
docker volume create local_registry
|
|
|
|
docker run -d \
|
2020-08-29 04:54:40 +00:00
|
|
|
--name registry-localhost \
|
2020-08-29 16:38:44 +00:00
|
|
|
--net "k3d-$cluster_name" \
|
2021-08-26 16:42:10 +00:00
|
|
|
--ip 172.18.1.1 \
|
2020-08-02 03:14:58 +00:00
|
|
|
--volume local_registry:/var/lib/registry \
|
|
|
|
--restart always \
|
|
|
|
-p 5000:5000 \
|
|
|
|
registry:2
|
|
|
|
fi
|
|
|
|
|
2021-08-26 16:42:10 +00:00
|
|
|
# local postgres database
|
|
|
|
if ! docker ps -a | grep postgres-localhost &>/dev/null; then
|
|
|
|
docker volume create local_postgres
|
2020-08-11 04:37:20 +00:00
|
|
|
docker run -d \
|
2021-08-26 16:42:10 +00:00
|
|
|
--name postgres-localhost \
|
2020-08-29 16:38:44 +00:00
|
|
|
--net "k3d-$cluster_name" \
|
2021-08-26 16:42:10 +00:00
|
|
|
--ip 172.18.1.2 \
|
|
|
|
--volume local_postgres:/var/lib/postgresql/data \
|
|
|
|
--volume "$PWD/.postgres/initdb.sql:/docker-entrypoint-initdb.d/initdb.sql:ro" \
|
2020-08-11 04:37:20 +00:00
|
|
|
--restart always \
|
2021-08-26 16:42:10 +00:00
|
|
|
--env POSTGRES_PASSWORD=changeme \
|
|
|
|
-p 5432:5432 \
|
|
|
|
postgres:9.6
|
2020-08-11 04:37:20 +00:00
|
|
|
sleep 10
|
|
|
|
fi
|
|
|
|
|
2020-08-29 04:54:40 +00:00
|
|
|
# local nfs server
|
|
|
|
if ! docker ps -a | grep nfs-localhost &>/dev/null; then
|
|
|
|
docker volume create local_nfs
|
|
|
|
docker run -d \
|
|
|
|
--name nfs-localhost \
|
2020-08-29 16:38:44 +00:00
|
|
|
--net "k3d-$cluster_name" \
|
2021-08-26 16:42:10 +00:00
|
|
|
--ip 172.18.1.3 \
|
2020-08-29 04:54:40 +00:00
|
|
|
--volume nfs_local:/data \
|
|
|
|
--volume /lib/modules:/lib/modules:ro \
|
|
|
|
--restart always \
|
|
|
|
--cap-add SYS_ADMIN \
|
|
|
|
--cap-add SYS_MODULE \
|
|
|
|
--env NFS_EXPORT_0='/data *(rw,async,insecure,no_subtree_check,no_root_squash,fsid=0)' \
|
|
|
|
--env NFS_DISABLE_VERSION_3=YES \
|
|
|
|
--env NFS_LOG_LEVEL=DEBUG \
|
|
|
|
-p 2049:2049 \
|
|
|
|
erichough/nfs-server:2.2.1
|
|
|
|
sleep 10
|
|
|
|
fi
|
|
|
|
|
2020-08-02 03:14:58 +00:00
|
|
|
k3d kubeconfig merge "$cluster_name" --switch-context >/dev/null
|
|
|
|
kubectl apply -f "$auto_deploy_manifest"
|
2020-08-29 04:54:40 +00:00
|
|
|
kubectl get nodes
|