Skip to content

Commit d4c6c26

Browse files
authored
Merge pull request #841 from keel-hq/feature/000165-prepare-a-script-to
Prepare a script to start a kind/k3s instance that we can...
2 parents b8dbc25 + ddc2692 commit d4c6c26

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed

scripts/start-local-cluster.sh

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# =============================================================================
5+
# start-local-cluster.sh
6+
# Creates a local Kubernetes cluster using kind for Keel development
7+
# Usage: ./scripts/start-local-cluster.sh
8+
# =============================================================================
9+
10+
CLUSTER_NAME="keel-dev"
11+
KIND_VERSION="v0.20.0"
12+
13+
# Colors for output
14+
RED='\033[0;31m'
15+
GREEN='\033[0;32m'
16+
YELLOW='\033[1;33m'
17+
NC='\033[0m' # No Color
18+
19+
log_info() {
20+
echo -e "${GREEN}[INFO]${NC} $1"
21+
}
22+
23+
log_warn() {
24+
echo -e "${YELLOW}[WARN]${NC} $1"
25+
}
26+
27+
log_error() {
28+
echo -e "${RED}[ERROR]${NC} $1"
29+
}
30+
31+
# Check if Docker is installed and running
32+
check_docker() {
33+
if ! command -v docker &> /dev/null; then
34+
log_error "Docker is not installed. Please install Docker first."
35+
exit 1
36+
fi
37+
38+
if ! docker info &> /dev/null; then
39+
log_error "Docker is not running. Please start Docker first."
40+
exit 1
41+
fi
42+
43+
log_info "Docker is installed and running"
44+
}
45+
46+
# Install kind if not present
47+
install_kind() {
48+
if command -v kind &> /dev/null; then
49+
log_info "kind is already installed: $(kind version)"
50+
return
51+
fi
52+
53+
log_info "Installing kind ${KIND_VERSION}..."
54+
55+
# Detect OS and architecture
56+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
57+
ARCH=$(uname -m)
58+
case $ARCH in
59+
x86_64) ARCH="amd64" ;;
60+
aarch64|arm64) ARCH="arm64" ;;
61+
esac
62+
63+
curl -Lo /tmp/kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-${OS}-${ARCH}"
64+
chmod +x /tmp/kind
65+
sudo mv /tmp/kind /usr/local/bin/kind
66+
67+
log_info "kind installed successfully"
68+
}
69+
70+
# Check if kubectl is available
71+
check_kubectl() {
72+
if ! command -v kubectl &> /dev/null; then
73+
log_warn "kubectl is not installed. Installing..."
74+
75+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
76+
ARCH=$(uname -m)
77+
case $ARCH in
78+
x86_64) ARCH="amd64" ;;
79+
aarch64|arm64) ARCH="arm64" ;;
80+
esac
81+
82+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/${OS}/${ARCH}/kubectl"
83+
chmod +x kubectl
84+
sudo mv kubectl /usr/local/bin/kubectl
85+
fi
86+
87+
log_info "kubectl is available: $(kubectl version --client --short 2>/dev/null || kubectl version --client)"
88+
}
89+
90+
# Create cluster if it doesn't exist
91+
create_cluster() {
92+
if kind get clusters 2>/dev/null | grep -q "^${CLUSTER_NAME}$"; then
93+
log_info "Cluster '${CLUSTER_NAME}' already exists"
94+
return
95+
fi
96+
97+
log_info "Creating kind cluster '${CLUSTER_NAME}'..."
98+
kind create cluster --name "${CLUSTER_NAME}"
99+
log_info "Cluster created successfully"
100+
}
101+
102+
# Verify cluster is working
103+
verify_cluster() {
104+
log_info "Verifying cluster..."
105+
106+
# Set kubectl context
107+
kubectl config use-context "kind-${CLUSTER_NAME}" &> /dev/null
108+
109+
# Wait for node to be ready
110+
log_info "Waiting for node to be ready..."
111+
kubectl wait --for=condition=Ready node --all --timeout=60s
112+
113+
echo ""
114+
kubectl get nodes
115+
echo ""
116+
}
117+
118+
# Print usage instructions
119+
print_instructions() {
120+
echo ""
121+
echo "=============================================="
122+
echo -e "${GREEN}✅ Local Kubernetes cluster is ready!${NC}"
123+
echo "=============================================="
124+
echo ""
125+
echo "Cluster name: ${CLUSTER_NAME}"
126+
echo "Context: kind-${CLUSTER_NAME}"
127+
echo ""
128+
echo "To run Keel against this cluster:"
129+
echo ""
130+
echo " cd cmd/keel && go build && ./keel --no-incluster"
131+
echo ""
132+
echo " # Or use make:"
133+
echo " make run"
134+
echo ""
135+
echo "To delete the cluster when done:"
136+
echo ""
137+
echo " kind delete cluster --name ${CLUSTER_NAME}"
138+
echo ""
139+
}
140+
141+
# Main
142+
main() {
143+
echo ""
144+
echo "🚀 Setting up local Kubernetes cluster for Keel development"
145+
echo ""
146+
147+
check_docker
148+
install_kind
149+
check_kubectl
150+
create_cluster
151+
verify_cluster
152+
print_instructions
153+
}
154+
155+
main "$@"

0 commit comments

Comments
 (0)