khuedoan-homelab/infra/bootstrap.sh

73 lines
2.0 KiB
Bash
Raw Normal View History

2021-07-18 16:12:13 +07:00
#!/bin/sh
2021-07-21 00:15:26 +07:00
set -euo pipefail
2021-07-18 16:12:13 +07:00
# Create ephemeral cluster
kind create cluster \
--wait 60s \
2021-07-21 00:15:26 +07:00
--kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \
--config ephemeral-cluster/kind.yaml
2021-07-18 16:12:13 +07:00
# Install Sidero
clusterctl init \
--bootstrap talos \
--control-plane talos \
--infrastructure sidero \
2021-07-21 00:15:26 +07:00
--kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \
--config clusterctl.yaml
2021-07-24 02:33:02 +07:00
# Create DHCP server
# kubectl create configmap dhcp-server \
# --kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \
# --from-file dhcp-server/dhcpd.conf
# kubectl apply \
# --kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \
# --filename dhcp-server/deployment.yaml
docker run --detach \
--name bootstrap-dhcp-server \
--network=host \
--volume $PWD/dhcp-server/dhcpd.conf:/data/dhcpd.conf \
networkboot/dhcpd:1.1.0
# Wait for all pods to be ready
kubectl wait pods \
2021-07-21 00:15:26 +07:00
--kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \
--all \
--all-namespaces \
2021-07-21 00:15:26 +07:00
--timeout 300s \
--for=condition=Ready
# Apply server classes
kubectl apply \
2021-07-21 00:15:26 +07:00
--kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \
--filename serverclasses/
# Waker servers up
wol '00:23:24:d1:f3:f0'
# wol '00:23:24:d1:f4:d6'
# wol '00:23:24:d1:f5:69'
# wol '00:23:24:e7:04:60'
2021-07-18 16:12:13 +07:00
# Create cluster
2021-07-21 00:15:26 +07:00
export CONTROL_PLANE_ENDPOINT=$(kubectl get server \
--kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \
--output jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')
clusterctl config cluster \
--infrastructure sidero \
2021-07-21 00:15:26 +07:00
--kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \
--config clusterctl.yaml \
homelab > cluster/homelab.yaml
kubectl apply \
2021-07-21 00:15:26 +07:00
--kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \
--filename cluster/homelab.yaml
2021-07-18 18:37:40 +07:00
# Get kube config
2021-07-21 00:15:26 +07:00
clusterctl get kubeconfig \
--kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \
homelab > kubeconfig.yaml
# Cleanup ephemeral cluster
2021-07-24 02:33:02 +07:00
kind delete cluster --name bootstrap-cluster
rm ephemeral-cluster/kind-kubeconfig.yaml
docker rm --force bootstrap-dhcp-server