2020-08-02 03:14:58 +00:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
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:
|
|
|
|
"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 \
|
|
|
|
--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
|
|
|
|
if ! docker ps -a | grep registry.localhost &>/dev/null; then
|
|
|
|
docker volume create local_registry
|
|
|
|
docker run -d \
|
|
|
|
--name registry.localhost \
|
|
|
|
--volume local_registry:/var/lib/registry \
|
|
|
|
--restart always \
|
|
|
|
-p 5000:5000 \
|
|
|
|
registry:2
|
|
|
|
docker network connect "k3d-$cluster_name" registry.localhost
|
|
|
|
fi
|
|
|
|
|
2020-08-11 04:37:20 +00:00
|
|
|
# local mariadb database
|
|
|
|
if ! docker ps -a | grep mariadb.localhost &>/dev/null; then
|
|
|
|
docker volume create local_mariadb
|
|
|
|
docker run -d \
|
|
|
|
--name mariadb.localhost \
|
|
|
|
--volume local_mariadb:/var/lib/mysql \
|
|
|
|
--restart always \
|
|
|
|
--env MYSQL_ROOT_PASSWORD=changeme \
|
|
|
|
-p 3306:3306 \
|
|
|
|
mariadb:10.5
|
|
|
|
docker network connect "k3d-$cluster_name" mariadb.localhost
|
|
|
|
sleep 10
|
|
|
|
fi
|
|
|
|
|
|
|
|
docker exec mariadb.localhost mysql -vv -uroot -pchangeme -e "
|
|
|
|
CREATE DATABASE IF NOT EXISTS gitea;
|
|
|
|
CREATE USER IF NOT EXISTS 'gitea'@'%' IDENTIFIED BY 'changeme';
|
|
|
|
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'%';
|
|
|
|
|
|
|
|
CREATE DATABASE IF NOT EXISTS grafana;
|
|
|
|
CREATE USER IF NOT EXISTS 'grafana'@'%' IDENTIFIED BY 'changeme';
|
|
|
|
GRANT ALL PRIVILEGES ON grafana.* TO 'grafana'@'%';
|
|
|
|
|
|
|
|
CREATE DATABASE IF NOT EXISTS nextcloud;
|
|
|
|
CREATE USER IF NOT EXISTS 'nextcloud'@'%' IDENTIFIED BY 'changeme';
|
|
|
|
GRANT ALL PRIVILEGES ON grafana.* TO 'nextcloud'@'%';
|
|
|
|
|
|
|
|
FLUSH PRIVILEGES;
|
|
|
|
"
|
|
|
|
|
2020-08-02 03:14:58 +00:00
|
|
|
k3d kubeconfig merge "$cluster_name" --switch-context >/dev/null
|
|
|
|
kubectl apply -f "$auto_deploy_manifest"
|
|
|
|
kubectl get nodes
|