1
0
Fork 0

use k3d for local cluster deployment

This commit is contained in:
Massaki Archambault 2020-08-01 23:14:58 -04:00
parent 6b0510e8fc
commit a3938f492b
6 changed files with 61 additions and 14 deletions

View File

@ -17,9 +17,9 @@ ifeq ($(environment),prod)
KUSTOMIZEDIR = kustomize/overlays/prod
KUSTOMIZEOUT = $(OUTDIR)/$(environment)/manifest.yaml
# base-deploy
KUSTOMIZEDIRALL = kustomize/overlays/prod-base-deploy
KUSTOMIZEOUTALL = $(OUTDIR)/$(environment)/base-deploy.yaml
# auto-deploy
KUSTOMIZEDIRALL = kustomize/overlays/prod-auto-deploy
KUSTOMIZEOUTALL = $(OUTDIR)/$(environment)/auto-deploy.yaml
else
environment = dev
@ -28,14 +28,14 @@ else
KUSTOMIZEDIR = kustomize/overlays/dev
KUSTOMIZEOUT = $(OUTDIR)/$(environment)/manifest.yaml
# base-deploy
KUSTOMIZEDIRALL = kustomize/overlays/dev-base-deploy
KUSTOMIZEOUTALL = $(OUTDIR)/$(environment)/base-deploy.yaml
# auto-deploy
KUSTOMIZEDIRALL = kustomize/overlays/dev-auto-deploy
KUSTOMIZEOUTALL = $(OUTDIR)/$(environment)/auto-deploy.yaml
endif
.PHONY: all info base-deploy clean diff apply
.PHONY: all info auto-deploy clean diff apply
all: info base-deploy $(KUSTOMIZEOUT)
all: info auto-deploy $(KUSTOMIZEOUT)
info:
@echo "Building for" $(environment)
@ -43,7 +43,7 @@ info:
clean:
rm -r $(OUTDIR)
base-deploy: $(SRC)
auto-deploy: $(SRC)
@mkdir -p $(dir $(KUSTOMIZEOUTALL))
$(KUSTOMIZE) build $(KUSTOMIZEFLAGS) $(KUSTOMIZEDIRALL) >$(KUSTOMIZEOUTALL) || (rm $(KUSTOMIZEOUTALL); exit 1)

View File

@ -1,4 +1,4 @@
bases:
- ../../bases/cert-manager
namespace: cert-manager
# namespace: cert-manager

View File

@ -1,4 +1,4 @@
bases:
- ../../bases/ingress-nginx
namespace: ingress-nginx
# namespace: ingress-nginx

View File

@ -4,4 +4,4 @@ bases:
# allow "kubectl apply -l managed-by=k3s --prune ..."
commonlabels:
managed-by: k3s
managed-by: auto-deploy

49
setup-dev-cluster.sh Executable file
View File

@ -0,0 +1,49 @@
#!/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" \
-p 8080:80@loadbalancer
sleep 1
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
k3d kubeconfig merge "$cluster_name" --switch-context >/dev/null
kubectl apply -f "$auto_deploy_manifest"
kubectl get nodes

View File

@ -1,2 +0,0 @@
#/bin/bash
cp /host/build/all/* /manifests