From 49cdd21e9098f57a243d72bf60c2e91e09fef0e7 Mon Sep 17 00:00:00 2001 From: Khue Doan Date: Sat, 24 Jul 2021 04:35:45 +0700 Subject: [PATCH] Automatically pivot management plane to new cluster --- infra/bootstrap.sh | 70 +++++++++++++++++++++++++------------- infra/cluster/homelab.yaml | 2 +- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/infra/bootstrap.sh b/infra/bootstrap.sh index fb8307af..255eafc4 100755 --- a/infra/bootstrap.sh +++ b/infra/bootstrap.sh @@ -8,20 +8,19 @@ kind create cluster \ --kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \ --config ephemeral-cluster/kind.yaml +export KUBECONFIG="$PWD/ephemeral-cluster/kind-kubeconfig.yaml" + # Install Sidero clusterctl init \ --bootstrap talos \ --control-plane talos \ --infrastructure sidero \ - --kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \ --config clusterctl.yaml # 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 \ @@ -31,7 +30,6 @@ docker run --detach \ # Wait for all pods to be ready kubectl wait pods \ - --kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \ --all \ --all-namespaces \ --timeout 300s \ @@ -39,33 +37,59 @@ kubectl wait pods \ # Apply server classes kubectl apply \ - --kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \ --filename serverclasses/ # Waker servers up wol '00:23:24:d1:f3:f0' + +# Create cluster +while true; do + kubectl get server --output jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}' && break +done + +export CONTROL_PLANE_ENDPOINT=$(kubectl get server \ + --output jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}') && break + +clusterctl config cluster \ + --infrastructure sidero \ + --config clusterctl.yaml \ + homelab | kubectl apply --filename - + +# Get kube config +while true; do + clusterctl get kubeconfig homelab > cluster/homelab-kubeconfig.yaml && break +done + +export KUBECONFIG="$PWD/cluster/homelab-kubeconfig.yaml" + +while true; do + kubectl cluster-info && break +done + +# Pivot Sidero to new cluster +clusterctl init \ + --bootstrap talos \ + --control-plane talos \ + --infrastructure sidero \ + --kubeconfig cluster/homelab-kubeconfig.yaml \ + --config clusterctl.yaml + +clusterctl move \ + --kubeconfig=ephemeral-cluster/kind-kubeconfig.yaml \ + --to-kubeconfig=cluster/homelab-kubeconfig.yaml + +# clusterctl config cluster \ +# --infrastructure sidero \ +# --config clusterctl.yaml \ +# --config clusterctl.yaml \ +# --worker-machine-count 3 \ +# homelab > cluster/homelab.yaml +# kubectl apply --filename cluster/homelab.yaml + # wol '00:23:24:d1:f4:d6' # wol '00:23:24:d1:f5:69' # wol '00:23:24:e7:04:60' -# Create cluster -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 \ - --kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \ - --config clusterctl.yaml \ - homelab > cluster/homelab.yaml -kubectl apply \ - --kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \ - --filename cluster/homelab.yaml - -# Get kube config -clusterctl get kubeconfig \ - --kubeconfig ephemeral-cluster/kind-kubeconfig.yaml \ - homelab > kubeconfig.yaml - # Cleanup ephemeral cluster kind delete cluster --name bootstrap-cluster rm ephemeral-cluster/kind-kubeconfig.yaml diff --git a/infra/cluster/homelab.yaml b/infra/cluster/homelab.yaml index 25d89711..8a08761e 100644 --- a/infra/cluster/homelab.yaml +++ b/infra/cluster/homelab.yaml @@ -27,7 +27,7 @@ metadata: namespace: default spec: controlPlaneEndpoint: - host: 192.168.1.12 + host: null port: 6443 --- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3