Imporve the infra
This commit is contained in:
@@ -59,7 +59,7 @@ wait_for_pods() {
|
||||
# Function to handle cleanup
|
||||
cleanup() {
|
||||
print_status "Starting cleanup process..."
|
||||
|
||||
|
||||
# Delete Kubernetes namespace with timeout
|
||||
print_status "Deleting namespace bakery-ia..."
|
||||
if kubectl get namespace bakery-ia &>/dev/null; then
|
||||
@@ -74,7 +74,7 @@ cleanup() {
|
||||
else
|
||||
print_status "Namespace bakery-ia not found"
|
||||
fi
|
||||
|
||||
|
||||
# Delete Kind cluster
|
||||
print_status "Deleting Kind cluster..."
|
||||
if kind get clusters | grep -q "bakery-ia-local"; then
|
||||
@@ -83,7 +83,17 @@ cleanup() {
|
||||
else
|
||||
print_status "Kind cluster bakery-ia-local not found"
|
||||
fi
|
||||
|
||||
|
||||
# Stop local registry
|
||||
print_status "Stopping local registry..."
|
||||
if docker ps -a | grep -q "kind-registry"; then
|
||||
docker stop kind-registry 2>/dev/null || true
|
||||
docker rm kind-registry 2>/dev/null || true
|
||||
print_success "Local registry removed"
|
||||
else
|
||||
print_status "Local registry not found"
|
||||
fi
|
||||
|
||||
# Stop Colima
|
||||
print_status "Stopping Colima..."
|
||||
if colima list | grep -q "k8s-local"; then
|
||||
@@ -92,7 +102,7 @@ cleanup() {
|
||||
else
|
||||
print_status "Colima profile k8s-local not found"
|
||||
fi
|
||||
|
||||
|
||||
print_success "Cleanup completed!"
|
||||
echo "----------------------------------------"
|
||||
}
|
||||
@@ -119,36 +129,125 @@ check_config_files() {
|
||||
print_success "Configuration files check completed"
|
||||
}
|
||||
|
||||
# Function to create local registry
|
||||
create_local_registry() {
|
||||
local reg_name='kind-registry'
|
||||
local reg_port='5001'
|
||||
|
||||
print_status "Setting up local Docker registry..."
|
||||
|
||||
# Create registry container unless it already exists
|
||||
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
|
||||
print_status "Creating registry container on port ${reg_port}..."
|
||||
docker run \
|
||||
-d --restart=always \
|
||||
-p "127.0.0.1:${reg_port}:5000" \
|
||||
--name "${reg_name}" \
|
||||
registry:2
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Local registry created at localhost:${reg_port}"
|
||||
else
|
||||
print_error "Failed to create local registry"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
print_success "Local registry already running at localhost:${reg_port}"
|
||||
fi
|
||||
|
||||
# Store registry info for later use
|
||||
echo "${reg_name}:${reg_port}"
|
||||
}
|
||||
|
||||
# Function to connect registry to Kind
|
||||
connect_registry_to_kind() {
|
||||
local reg_name='kind-registry'
|
||||
local reg_port='5001'
|
||||
|
||||
print_status "Connecting registry to Kind network..."
|
||||
|
||||
# Connect the registry to the cluster network if not already connected
|
||||
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
|
||||
docker network connect "kind" "${reg_name}"
|
||||
print_success "Registry connected to Kind network"
|
||||
else
|
||||
print_success "Registry already connected to Kind network"
|
||||
fi
|
||||
|
||||
# Configure containerd in the Kind node to use the registry
|
||||
print_status "Configuring containerd to use local registry..."
|
||||
|
||||
# Create the registry config directory
|
||||
docker exec bakery-ia-local-control-plane mkdir -p /etc/containerd/certs.d/localhost:${reg_port}
|
||||
|
||||
# Add registry configuration
|
||||
docker exec bakery-ia-local-control-plane sh -c "cat > /etc/containerd/certs.d/localhost:${reg_port}/hosts.toml <<EOF
|
||||
server = \"http://localhost:${reg_port}\"
|
||||
|
||||
[host.\"http://${reg_name}:5000\"]
|
||||
capabilities = [\"pull\", \"resolve\", \"push\"]
|
||||
skip_verify = true
|
||||
EOF"
|
||||
|
||||
# Restart containerd to pick up new configuration
|
||||
docker exec bakery-ia-local-control-plane systemctl restart containerd
|
||||
|
||||
print_success "Containerd configured for local registry"
|
||||
|
||||
# Document the local registry
|
||||
print_status "Documenting local registry in cluster..."
|
||||
kubectl apply -f - <<EOF
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: local-registry-hosting
|
||||
namespace: kube-public
|
||||
data:
|
||||
localRegistryHosting.v1: |
|
||||
host: "localhost:${reg_port}"
|
||||
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
|
||||
EOF
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Registry documented in cluster"
|
||||
else
|
||||
print_warning "Failed to document registry (non-critical)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to handle setup
|
||||
setup() {
|
||||
print_status "Starting setup process..."
|
||||
|
||||
|
||||
# Check for required config files
|
||||
check_config_files
|
||||
|
||||
|
||||
# 1. Start Colima with adequate resources
|
||||
print_status "Starting Colima with 6 CPU, 12GB memory, 120GB disk..."
|
||||
colima start --cpu 6 --memory 12 --disk 120 --runtime docker --profile k8s-local
|
||||
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Colima started successfully"
|
||||
else
|
||||
print_error "Failed to start Colima"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. Create Kind cluster using existing configuration
|
||||
print_status "Creating Kind cluster with existing configuration..."
|
||||
|
||||
|
||||
# 2. Create local registry before Kind cluster
|
||||
create_local_registry
|
||||
|
||||
# 3. Create Kind cluster using existing configuration with registry support
|
||||
print_status "Creating Kind cluster with registry configuration..."
|
||||
|
||||
if [ -f kind-config.yaml ]; then
|
||||
print_status "Using existing kind-config.yaml file"
|
||||
|
||||
print_status "Using kind-config.yaml with local registry support"
|
||||
|
||||
# Extract cluster name from config for verification
|
||||
CLUSTER_NAME=$(grep -E "name:\s*" kind-config.yaml | head -1 | sed 's/name:\s*//' | tr -d '[:space:]' || echo "bakery-ia-local")
|
||||
|
||||
|
||||
print_status "Creating cluster: $CLUSTER_NAME"
|
||||
kind create cluster --config kind-config.yaml
|
||||
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Kind cluster created successfully"
|
||||
else
|
||||
@@ -159,6 +258,9 @@ setup() {
|
||||
print_error "kind-config.yaml file not found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. Connect registry to Kind network
|
||||
connect_registry_to_kind
|
||||
|
||||
# 3. Install NGINX Ingress Controller
|
||||
print_status "Installing NGINX Ingress Controller..."
|
||||
@@ -220,6 +322,7 @@ setup() {
|
||||
print_status "Cluster Information:"
|
||||
echo " - Colima profile: k8s-local"
|
||||
echo " - Kind cluster: $CLUSTER_NAME"
|
||||
echo " - Local registry: localhost:5001"
|
||||
echo " - Direct port mappings (from kind-config.yaml):"
|
||||
echo " Frontend: localhost:3000 -> container:30300"
|
||||
echo " Gateway: localhost:8000 -> container:30800"
|
||||
@@ -234,6 +337,11 @@ setup() {
|
||||
echo " - Use Ingress via: http://localhost:${HTTP_HOST_PORT}"
|
||||
echo " - Direct NodePort: http://localhost:30080"
|
||||
echo "----------------------------------------"
|
||||
print_status "Local Registry Information:"
|
||||
echo " - Registry URL: localhost:5001"
|
||||
echo " - Images will be pushed to: localhost:5001/bakery/<service>"
|
||||
echo " - Update your Tiltfile with: default_registry('localhost:5001')"
|
||||
echo "----------------------------------------"
|
||||
}
|
||||
|
||||
# Function to show usage
|
||||
|
||||
Reference in New Issue
Block a user