-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·210 lines (188 loc) · 6.78 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·210 lines (188 loc) · 6.78 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
# KubeStellar Console - Deploy to Kubernetes
#
# Deploys KubeStellar Console to any Kubernetes cluster via Helm.
# Works with OpenShift, EKS, GKE, AKS, kind, k3s, or any distribution.
#
# Recommended (verify before execute):
# curl -sSL https://raw.githubusercontent.com/kubestellar/console/main/deploy.sh -o deploy.sh
# curl -sSL https://raw.githubusercontent.com/kubestellar/console/main/deploy.sh.sha256 -o deploy.sh.sha256
# sha256sum -c deploy.sh.sha256
# bash deploy.sh
#
# Quick (pipe to bash — skips integrity check):
# curl -sSL https://raw.githubusercontent.com/kubestellar/console/main/deploy.sh | bash
#
# Options:
# --context, -c <name> Kubernetes context (default: current context)
# --namespace, -n <name> Namespace (default: kubestellar-console)
# --release, -r <name> Helm release name (default: kc)
# --version, -v <version> Chart version (default: latest)
# --set <key=value> Pass additional Helm --set values
# --openshift Enable OpenShift Route instead of port-forward
# --ingress <host> Enable Ingress with the given hostname
# --github-oauth Prompt for GitHub OAuth credentials
# --uninstall Remove the console from the cluster
#
# Environment variables (alternative to flags):
# GITHUB_CLIENT_ID GitHub OAuth client ID
# GITHUB_CLIENT_SECRET GitHub OAuth client secret
# CLAUDE_API_KEY Claude API key for AI features
set -e
# --- Defaults ---
NAMESPACE="kubestellar-console"
RELEASE="kc"
CHART_VERSION=""
CONTEXT=""
HELM_REPO="kubestellar-console"
HELM_REPO_URL="https://kubestellar.github.io/console"
CHART="kubestellar-console/kubestellar-console"
OPENSHIFT=false
INGRESS_HOST=""
GITHUB_OAUTH=false
UNINSTALL=false
EXTRA_SETS=()
# --- Parse args ---
while [[ $# -gt 0 ]]; do
case $1 in
--context|-c) CONTEXT="$2"; shift 2 ;;
--namespace|-n) NAMESPACE="$2"; shift 2 ;;
--release|-r) RELEASE="$2"; shift 2 ;;
--version|-v) CHART_VERSION="$2"; shift 2 ;;
--set) EXTRA_SETS+=("--set" "$2"); shift 2 ;;
--openshift) OPENSHIFT=true; shift ;;
--ingress) INGRESS_HOST="$2"; shift 2 ;;
--github-oauth) GITHUB_OAUTH=true; shift ;;
--uninstall) UNINSTALL=true; shift ;;
*) shift ;;
esac
done
# --- Context flag ---
KUBE_ARGS=()
if [ -n "$CONTEXT" ]; then
KUBE_ARGS=("--kube-context" "$CONTEXT")
fi
# --- Uninstall ---
if [ "$UNINSTALL" = true ]; then
echo "=== Uninstalling KubeStellar Console ==="
echo ""
helm uninstall "$RELEASE" --namespace "$NAMESPACE" "${KUBE_ARGS[@]}" 2>/dev/null || echo " Release not found"
kubectl delete namespace "$NAMESPACE" "${KUBE_ARGS[@]/#--kube-context/--context}" 2>/dev/null || echo " Namespace not found"
echo ""
echo "Done."
exit 0
fi
# --- Prerequisites ---
echo "=== KubeStellar Console — Deploy to Kubernetes ==="
echo ""
for cmd in helm kubectl; do
if ! command -v "$cmd" &>/dev/null; then
echo "Error: $cmd is required but not found."
echo " Install Helm: https://helm.sh/docs/intro/install/"
echo " Install kubectl: https://kubernetes.io/docs/tasks/tools/"
exit 1
fi
done
# Verify cluster connectivity
CURRENT_CTX=$(kubectl config current-context 2>/dev/null || true)
if [ -n "$CONTEXT" ]; then
echo " Context: $CONTEXT"
if ! kubectl cluster-info "${KUBE_ARGS[@]/#--kube-context/--context}" &>/dev/null 2>&1; then
echo "Error: Cannot connect to cluster with context '$CONTEXT'"
exit 1
fi
elif [ -n "$CURRENT_CTX" ]; then
echo " Context: $CURRENT_CTX (current)"
else
echo "Error: No Kubernetes context found. Set one with --context or kubectl config use-context."
exit 1
fi
echo " Namespace: $NAMESPACE"
echo " Release: $RELEASE"
echo ""
# --- Add Helm repo ---
echo "Adding Helm repository..."
helm repo add "$HELM_REPO" "$HELM_REPO_URL" 2>/dev/null || true
helm repo update "$HELM_REPO" >/dev/null 2>&1
echo ""
# --- Build Helm values ---
HELM_ARGS=("--namespace" "$NAMESPACE" "--create-namespace")
HELM_ARGS+=("${KUBE_ARGS[@]}")
if [ -n "$CHART_VERSION" ]; then
HELM_ARGS+=("--version" "$CHART_VERSION")
fi
# GitHub OAuth
if [ "$GITHUB_OAUTH" = true ] && [ -z "$GITHUB_CLIENT_ID" ]; then
echo "--- GitHub OAuth Setup ---"
echo "Create an OAuth App at: https://github.com/settings/developers"
echo ""
read -rp " GitHub Client ID: " GITHUB_CLIENT_ID
read -rp " GitHub Client Secret: " GITHUB_CLIENT_SECRET
echo ""
fi
if [ -n "$GITHUB_CLIENT_ID" ] && [ -n "$GITHUB_CLIENT_SECRET" ]; then
HELM_ARGS+=("--set" "github.clientId=$GITHUB_CLIENT_ID")
HELM_ARGS+=("--set" "github.clientSecret=$GITHUB_CLIENT_SECRET")
echo " GitHub OAuth: enabled"
else
echo " GitHub OAuth: disabled (auto-login as dev-user)"
fi
# Claude AI
if [ -n "$CLAUDE_API_KEY" ]; then
HELM_ARGS+=("--set" "claude.apiKey=$CLAUDE_API_KEY")
echo " Claude AI: enabled"
fi
# OpenShift Route
if [ "$OPENSHIFT" = true ]; then
HELM_ARGS+=("--set" "route.enabled=true")
echo " Exposure: OpenShift Route"
fi
# Ingress
if [ -n "$INGRESS_HOST" ]; then
HELM_ARGS+=("--set" "ingress.enabled=true")
HELM_ARGS+=("--set" "ingress.hosts[0].host=$INGRESS_HOST")
HELM_ARGS+=("--set" "ingress.hosts[0].paths[0].path=/")
HELM_ARGS+=("--set" "ingress.hosts[0].paths[0].pathType=Prefix")
echo " Exposure: Ingress ($INGRESS_HOST)"
fi
# Extra --set values
HELM_ARGS+=("${EXTRA_SETS[@]}")
echo ""
# --- Install or Upgrade ---
echo "Deploying..."
if helm status "$RELEASE" --namespace "$NAMESPACE" "${KUBE_ARGS[@]}" >/dev/null 2>&1; then
helm upgrade "$RELEASE" "$CHART" "${HELM_ARGS[@]}" --wait --timeout 120s
else
helm install "$RELEASE" "$CHART" "${HELM_ARGS[@]}" --wait --timeout 120s
fi
echo ""
echo "=== KubeStellar Console is deployed ==="
echo ""
# --- Access instructions ---
if [ "$OPENSHIFT" = true ]; then
ROUTE_HOST=$(kubectl get route "$RELEASE-kubestellar-console" \
--namespace "$NAMESPACE" \
"${KUBE_ARGS[@]/#--kube-context/--context}" \
-o jsonpath='{.spec.host}' 2>/dev/null || true)
if [ -n "$ROUTE_HOST" ]; then
echo " URL: https://$ROUTE_HOST"
else
echo " Route created — check: kubectl get route -n $NAMESPACE"
fi
elif [ -n "$INGRESS_HOST" ]; then
echo " URL: https://$INGRESS_HOST"
echo " (Ensure DNS and Ingress controller are configured)"
else
echo " To access the console, run:"
echo ""
CTX_FLAG=""
if [ -n "$CONTEXT" ]; then
CTX_FLAG=" --context $CONTEXT"
fi
echo " kubectl port-forward${CTX_FLAG} -n $NAMESPACE svc/$RELEASE-kubestellar-console 8080:8080"
echo ""
echo " Then open: http://localhost:8080"
fi
echo ""
echo "To uninstall: $0 --uninstall${CONTEXT:+ --context $CONTEXT}"
echo ""