fixes
This commit is contained in:
@@ -1,64 +1,3 @@
|
|||||||
# =============================================================================
|
|
||||||
# UpCloud Workload Cluster
|
|
||||||
# =============================================================================
|
|
||||||
# A lean UCS cluster for running application workloads. No managed data
|
|
||||||
# services — those live on the platform cluster. ArgoCD (on the platform
|
|
||||||
# cluster) deploys apps to this cluster via the app-of-apps pattern.
|
|
||||||
#
|
|
||||||
# Platform components deployed by deploy-workload.sh:
|
|
||||||
# nginx-ingress, cert-manager, external-dns, external-secrets, alloy
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
# tofu init && tofu plan && tofu apply
|
|
||||||
# ./sync-tofu-outputs.sh --env upcloud-workload
|
|
||||||
# ./deploy-workload.sh --env upcloud-workload
|
|
||||||
# =============================================================================
|
|
||||||
|
|
||||||
variable "prefix" {
|
|
||||||
description = "Prefix for resource names"
|
|
||||||
type = string
|
|
||||||
default = "clst-workload"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "zone" {
|
|
||||||
description = "UpCloud zone"
|
|
||||||
type = string
|
|
||||||
default = "no-svg1"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "node_plan" {
|
|
||||||
description = "UpCloud server plan for worker nodes"
|
|
||||||
type = string
|
|
||||||
default = "2xCPU-4GB"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "node_count" {
|
|
||||||
description = "Number of worker nodes"
|
|
||||||
type = number
|
|
||||||
default = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "network_cidr" {
|
|
||||||
description = "CIDR block for the private network"
|
|
||||||
type = string
|
|
||||||
default = "10.110.0.0/24"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "control_plane_ip_filter" {
|
|
||||||
description = "CIDRs allowed to access the K8s API"
|
|
||||||
type = list(string)
|
|
||||||
default = ["0.0.0.0/0"]
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "tags" {
|
|
||||||
description = "Labels to apply to resources"
|
|
||||||
type = map(string)
|
|
||||||
default = {
|
|
||||||
Environment = "workload"
|
|
||||||
ManagedBy = "tofu"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module "cluster" {
|
module "cluster" {
|
||||||
source = "../modules/cluster"
|
source = "../modules/cluster"
|
||||||
|
|
||||||
@@ -76,45 +15,3 @@ module "cluster" {
|
|||||||
ManagedBy = "tofu"
|
ManagedBy = "tofu"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─── Networking ───────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
resource "upcloud_router" "kubernetes" {
|
|
||||||
name = "${var.prefix}-workload-router"
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "upcloud_gateway" "kubernetes" {
|
|
||||||
name = "${var.prefix}-workload-gateway"
|
|
||||||
zone = var.zone
|
|
||||||
features = ["nat"]
|
|
||||||
router {
|
|
||||||
id = upcloud_router.kubernetes.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "upcloud_network" "kubernetes" {
|
|
||||||
name = "${var.prefix}-workload-network"
|
|
||||||
zone = var.zone
|
|
||||||
router = upcloud_router.kubernetes.id
|
|
||||||
|
|
||||||
ip_network {
|
|
||||||
address = var.network_cidr
|
|
||||||
dhcp = true
|
|
||||||
dhcp_default_route = true
|
|
||||||
family = "IPv4"
|
|
||||||
gateway = cidrhost(var.network_cidr, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
depends_on = [upcloud_gateway.kubernetes]
|
|
||||||
}
|
|
||||||
|
|
||||||
# ─── Kubernetes Cluster ───────────────────────────────────────────────
|
|
||||||
|
|
||||||
resource "upcloud_kubernetes_cluster" "main-prod" {
|
|
||||||
name = "${var.prefix}-workload"
|
|
||||||
zone = var.zone
|
|
||||||
network = upcloud_network.kubernetes.id
|
|
||||||
control_plane_ip_filter = var.control_plane_ip_filter
|
|
||||||
|
|
||||||
private_node_groups = true
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,9 +5,56 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|||||||
TOFU_ROOT="$(dirname "$SCRIPT_DIR")"
|
TOFU_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||||
PROJECT_ROOT="$(dirname "$TOFU_ROOT")"
|
PROJECT_ROOT="$(dirname "$TOFU_ROOT")"
|
||||||
|
|
||||||
CLUSTER="${1:?Usage: $0 <cluster> (e.g., aks-dev, eks-prod)}"
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $0 <cluster> --envtype <dev|prod|workload>
|
||||||
|
|
||||||
|
Fetch (or reuse) a kubeconfig for the given cluster.
|
||||||
|
Platform is read from the cluster prefix (<platform>-...).
|
||||||
|
Env type must be supplied explicitly — it is no longer inferred
|
||||||
|
from the cluster name, so names like 'upc-forte-group' work.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
$0 aks-dev --envtype dev
|
||||||
|
$0 upc-forte-group --envtype prod
|
||||||
|
$0 eks-workload --envtype workload
|
||||||
|
EOF
|
||||||
|
exit "${1:-0}"
|
||||||
|
}
|
||||||
|
|
||||||
|
CLUSTER=""
|
||||||
|
ENVTYPE=""
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--envtype) ENVTYPE="${2:-}"; shift 2 ;;
|
||||||
|
--envtype=*) ENVTYPE="${1#*=}"; shift ;;
|
||||||
|
-h|--help) usage 0 ;;
|
||||||
|
-*) echo "Unknown option: $1"; usage 1 ;;
|
||||||
|
*)
|
||||||
|
if [[ -z "$CLUSTER" ]]; then
|
||||||
|
CLUSTER="$1"; shift
|
||||||
|
else
|
||||||
|
echo "Error: unexpected argument '$1'"; usage 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ -z "$CLUSTER" ]] && { echo "Error: <cluster> argument required"; usage 1; }
|
||||||
|
[[ -z "$ENVTYPE" ]] && { echo "Error: --envtype <dev|prod|workload> required"; usage 1; }
|
||||||
|
|
||||||
|
case "$ENVTYPE" in
|
||||||
|
dev|prod|workload) ;;
|
||||||
|
*) echo "Error: invalid --envtype '$ENVTYPE'. Expected: dev, prod, workload"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
PLATFORM="${CLUSTER%%-*}"
|
PLATFORM="${CLUSTER%%-*}"
|
||||||
ENV="${CLUSTER#*-}"
|
ENV="$ENVTYPE"
|
||||||
|
|
||||||
|
case "$PLATFORM" in
|
||||||
|
aks|eks|gke|upc) ;;
|
||||||
|
*) echo "Error: unknown platform '$PLATFORM'. Expected: aks, eks, gke, upc"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
KUBECONFIG_FILE="$PROJECT_ROOT/private/$CLUSTER/kubeconfig"
|
KUBECONFIG_FILE="$PROJECT_ROOT/private/$CLUSTER/kubeconfig"
|
||||||
|
|
||||||
@@ -53,10 +100,6 @@ else
|
|||||||
CLUSTER_ID=$(tofu output -raw cluster_id 2>/dev/null || echo "${UPCLOUD_CLUSTER_ID:-}")
|
CLUSTER_ID=$(tofu output -raw cluster_id 2>/dev/null || echo "${UPCLOUD_CLUSTER_ID:-}")
|
||||||
upctl kubernetes config "$CLUSTER_ID" > "$KUBECONFIG_FILE"
|
upctl kubernetes config "$CLUSTER_ID" > "$KUBECONFIG_FILE"
|
||||||
;;
|
;;
|
||||||
*)
|
|
||||||
echo "Error: unknown platform '$PLATFORM'"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
chmod 600 "$KUBECONFIG_FILE"
|
chmod 600 "$KUBECONFIG_FILE"
|
||||||
|
|||||||
@@ -8,26 +8,33 @@ PROJECT_ROOT="$(dirname "$TOFU_ROOT")"
|
|||||||
# ─── Usage ────────────────────────────────────────────────────────────
|
# ─── Usage ────────────────────────────────────────────────────────────
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
Usage: $0 <cluster> [options]
|
Usage: $0 <cluster> --envtype <dev|prod|workload> [options]
|
||||||
|
|
||||||
Provision a Kubernetes cluster using OpenTofu.
|
Provision a Kubernetes cluster using OpenTofu.
|
||||||
Mirrors bootstrap.sh convention: cluster = <platform>-<env>
|
Cluster name is opaque — platform is read from its prefix
|
||||||
|
(<platform>-...), env is taken from --envtype.
|
||||||
|
|
||||||
Clusters: aks-dev | aks-prod | eks-dev | eks-prod
|
Platforms (inferred from cluster prefix):
|
||||||
gke-dev | gke-prod | upc-dev | upc-prod
|
aks | eks | gke | upc
|
||||||
upc-forte-group
|
|
||||||
<platform>-workload (for workload clusters)
|
Env types (required via --envtype):
|
||||||
|
dev Platform cluster, development
|
||||||
|
prod Platform cluster, production
|
||||||
|
workload Lean cluster for application workloads (no managed data
|
||||||
|
services — those run on the platform cluster)
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
--envtype <type> dev | prod | workload (required)
|
||||||
--plan Plan only, don't apply
|
--plan Plan only, don't apply
|
||||||
--destroy Destroy the cluster (use teardown-cluster.sh instead)
|
--destroy Destroy the cluster (use teardown-cluster.sh instead)
|
||||||
--auto Skip confirmation prompts
|
--auto Skip confirmation prompts
|
||||||
-h, --help Show this help
|
-h, --help Show this help
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
$0 aks-dev
|
$0 aks-dev --envtype dev
|
||||||
$0 eks-prod --plan
|
$0 eks-prod --envtype prod --plan
|
||||||
$0 upc-dev --auto
|
$0 upc-forte-group --envtype prod --auto
|
||||||
|
$0 upc-workload --envtype workload
|
||||||
|
|
||||||
Prerequisites:
|
Prerequisites:
|
||||||
- tofu, kubectl, helm installed
|
- tofu, kubectl, helm installed
|
||||||
@@ -42,6 +49,7 @@ EOF
|
|||||||
|
|
||||||
# ─── Parse arguments ──────────────────────────────────────────────────
|
# ─── Parse arguments ──────────────────────────────────────────────────
|
||||||
CLUSTER=""
|
CLUSTER=""
|
||||||
|
ENVTYPE=""
|
||||||
PLAN_ONLY=false
|
PLAN_ONLY=false
|
||||||
DESTROY=false
|
DESTROY=false
|
||||||
AUTO_APPROVE=false
|
AUTO_APPROVE=false
|
||||||
@@ -51,6 +59,8 @@ while [[ $# -gt 0 ]]; do
|
|||||||
--plan) PLAN_ONLY=true; shift ;;
|
--plan) PLAN_ONLY=true; shift ;;
|
||||||
--destroy) DESTROY=true; shift ;;
|
--destroy) DESTROY=true; shift ;;
|
||||||
--auto) AUTO_APPROVE=true; shift ;;
|
--auto) AUTO_APPROVE=true; shift ;;
|
||||||
|
--envtype) ENVTYPE="${2:-}"; shift 2 ;;
|
||||||
|
--envtype=*) ENVTYPE="${1#*=}"; shift ;;
|
||||||
-h|--help) usage 0 ;;
|
-h|--help) usage 0 ;;
|
||||||
-*) echo "Unknown option: $1"; usage 1 ;;
|
-*) echo "Unknown option: $1"; usage 1 ;;
|
||||||
*)
|
*)
|
||||||
@@ -66,10 +76,16 @@ while [[ $# -gt 0 ]]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
[[ -z "$CLUSTER" ]] && { echo "Error: <cluster> argument required"; usage 1; }
|
[[ -z "$CLUSTER" ]] && { echo "Error: <cluster> argument required"; usage 1; }
|
||||||
|
[[ -z "$ENVTYPE" ]] && { echo "Error: --envtype <dev|prod|workload> required"; usage 1; }
|
||||||
|
|
||||||
# ─── Map cluster → platform + env ────────────────────────────────────
|
case "$ENVTYPE" in
|
||||||
PLATFORM="${CLUSTER%%-*}" # aks-dev → aks
|
dev|prod|workload) ;;
|
||||||
ENV="${CLUSTER#*-}" # aks-dev → dev
|
*) echo "Error: invalid --envtype '$ENVTYPE'. Expected: dev, prod, workload"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# ─── Resolve platform + env ───────────────────────────────────────────
|
||||||
|
PLATFORM="${CLUSTER%%-*}" # cluster prefix → platform (e.g. upc-forte-group → upc)
|
||||||
|
ENV="$ENVTYPE" # env comes from --envtype, not the cluster name
|
||||||
|
|
||||||
case "$PLATFORM" in
|
case "$PLATFORM" in
|
||||||
aks|eks|gke|upc) ;;
|
aks|eks|gke|upc) ;;
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
# in case of $'\r': command not found error, run command below first
|
# in case of $'\r': command not found error, run command below first
|
||||||
# sed -i 's/\r$//' ./bootstrap.sh
|
# sed -i 's/\r$//' ./bootstrap.sh
|
||||||
|
|
||||||
CLUSTER="${1:?Usage: ./bootstrap.sh <cluster> (upc-dev|upc-prod|upc-forte-group|aks-dev|aks-prod|eks-dev|eks-prod|gke-dev|gke-prod)}"
|
CLUSTER="${1:?Usage: ./bootstrap.sh <cluster> # e.g. upc-dev, upc-prod, upc-forte-group, aks-dev, eks-prod, gke-dev — must match clusters/<cluster>.yaml}"
|
||||||
|
|
||||||
echo "running $0 for cluster: ${CLUSTER}..."
|
echo "running $0 for cluster: ${CLUSTER}..."
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user