From 7c671e1ee5cb2e328416a4ace8f0e4b3ab16922b Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Tue, 6 Dec 2022 14:43:31 -0600 Subject: [PATCH] scale down vsphere-csi-controll deployment to 1 replica if < 3 control nodes --- terraform/main.tf | 1 + terraform/scripts/initialize-controlplane.sh | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index a99dd3b..23579e0 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -137,6 +137,7 @@ resource "vsphere_virtual_machine" "control" { "echo export K8S_POD_CIDR=\"'${var.k8s-pod-cidr}'\" >> env.txt", "echo export K8S_CLUSTER_NAME=\"'${var.k8s-cluster-name}'\" >> env.txt", "echo export K8S_CONTROLPLANE_VIP=\"'${var.k8s-controlplane-vip}'\" >> env.txt", + "echo export K8S_CONTROLPLANE_COUNT=\"'${var.vm-control-count}'\" >> env.txt", "echo export KUBEVIP_VER=\"'${var.k8s-kubevip-version}'\" >> env.txt", "echo export K8S_NODE_COUNT=\"'${local.k8s-node-count}'\" >> env.txt", "echo export VCENTER_SERVER=\"'${var.vsphere-server}'\" >> env.txt", diff --git a/terraform/scripts/initialize-controlplane.sh b/terraform/scripts/initialize-controlplane.sh index 19fd466..8a30755 100644 --- a/terraform/scripts/initialize-controlplane.sh +++ b/terraform/scripts/initialize-controlplane.sh @@ -343,10 +343,14 @@ datacenters = "${VCENTER_DATACENTER}" EOF kubectl create secret generic vsphere-config-secret --from-file=csi-vsphere.conf --namespace=vmware-system-csi - if kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/vsphere-csi-driver/v2.7.0/manifests/vanilla/vsphere-csi-driver.yaml; then + wget "https://raw.githubusercontent.com/kubernetes-sigs/vsphere-csi-driver/v2.7.0/manifests/vanilla/vsphere-csi-driver.yaml" + if [ "${K8S_CONTROLPLANE_COUNT}" -lt 3 ]; then + sed -i 's/replicas: 3/replicas: 1/' vsphere-csi-driver.yaml + fi + if kubectl apply -f vsphere-csi-driver.yaml; then echo ">> Cluster initialization complete!" touch .k8s-cluster-success - rm -f csi-vsphere.conf discovery.yaml env.txt kubeadminit.yaml initialize-controlplane.sh + rm -f csi-vsphere.conf discovery.yaml env.txt kubeadminit.yaml initialize-controlplane.sh vsphere-csi-driver.yaml else echo ">> [ERROR] Failed to configure CSI! <<" fi