-
Notifications
You must be signed in to change notification settings - Fork 3
/
y-cluster-provision-k3d
executable file
·50 lines (41 loc) · 2.02 KB
/
y-cluster-provision-k3d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
[ -z "$DEBUG" ] || set -x
set -eo pipefail
[ -z "$KUBECONFIG" ] && echo "Provision requires an explicit KUBECONFIG env" && exit 1
[ -z "$CONTEXTNAME" ] && CONTEXTNAME=local
K3D_NAME=ystack
[ -z "$YSTACK_HOST" ] && YSTACK_HOST=ystack.local
[ -z "$YSTACK_PORTS_IP" ] && export YSTACK_PORTS_IP=$(y-localhost $YSTACK_HOST show 2>/dev/null)
[ -z "$YSTACK_PORTS_IP" ] || echo "Will bind ports to $YSTACK_PORTS_IP $YSTACK_HOST"
[ -z "$K3D_MEMORY" ] && K3D_MEMORY="6G"
[ -z "$K3D_AGENTS" ] && K3D_AGENTS="0"
[ -z "$K3D_DOCKER_UPDATE" ] && K3D_DOCKER_UPDATE="--cpuset-cpus=3 --cpus=3"
y-k3d cluster create $K3D_NAME \
--registry-config "$YSTACK_HOME/k3s/docker-image/registries.yaml" \
--no-lb \
--agents="$K3D_AGENTS" \
--servers-memory="$K3D_MEMORY" \
$VM_RESOURCES
# TODO support agents >0
K3D_DOCKER_NAME=k3d-$K3D_NAME-server-0
docker update $K3D_DOCKER_NAME $K3D_DOCKER_UPDATE
docker inspect $K3D_DOCKER_NAME | grep Cpu
kubectl config delete-context local || true
# Could interfere with some k3d functionality. For example skaffold's k3d detection will probably not work.
kubectl config rename-context k3d-ystack $CONTEXTNAME
# y-cluster-assert-install --context=$CONTEXTNAME
# This list of bases also exists in ../k3s/docker-ystack-proxy/Dockerfile, and in y-cluster-provision-multipass
for base in \
00-ystack-namespace \
10-minio \
20-builds-registry \
21-prod-registry \
40-buildkit; do \
basepath="$YSTACK_HOME/k3s/$base/"
echo "# Applying $basepath ..."
kubectl --context=$CONTEXTNAME apply -k $basepath
done
BUILDS_REGISTRY_IP=$(kubectl --context=$CONTEXTNAME -n ystack get service builds-registry -o=jsonpath='{.spec.clusterIP}')
PROD_REGISTRY_IP=$(kubectl --context=$CONTEXTNAME -n ystack get service prod-registry -o=jsonpath='{.spec.clusterIP}')
docker exec k3d-ystack-server-0 sh -cex "echo '$BUILDS_REGISTRY_IP builds-registry.ystack.svc.cluster.local' >> /etc/hosts"
docker exec k3d-ystack-server-0 sh -cex "echo '$PROD_REGISTRY_IP prod-registry.ystack.svc.cluster.local' >> /etc/hosts"