-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-to-k8s.sh
More file actions
executable file
·62 lines (50 loc) · 2.02 KB
/
Copy pathdeploy-to-k8s.sh
File metadata and controls
executable file
·62 lines (50 loc) · 2.02 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
#!/bin/bash
# Deploy Calculator to Kubernetes
# This script sets up a local Kubernetes cluster and deploys the calculator app
set -e
echo "🚀 Deploying Simple Calculator to Kubernetes..."
# Check if kind cluster exists
if ! kind get clusters | grep -q "^kind$"; then
echo "📦 Creating kind cluster..."
kind create cluster --name kind
else
echo "✅ Kind cluster already exists"
fi
# Build Docker image
echo "🔨 Building Docker image..."
docker build -f docker/Dockerfile -t simple-calculator:latest .
# Load image into kind cluster
echo "📤 Loading image into kind cluster..."
kind load docker-image simple-calculator:latest --name kind
# Apply Kubernetes manifests
echo "☸️ Applying Kubernetes manifests..."
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
# Wait for deployment to be ready
echo "⏳ Waiting for deployment to be ready..."
kubectl wait --for=condition=available --timeout=60s deployment/simple-calculator
# Get service information
echo "📋 Getting service information..."
kubectl get pods -l app=simple-calculator
kubectl get services simple-calculator-service
# Get the service URL (for LoadBalancer type)
SERVICE_IP=$(kubectl get service simple-calculator-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
SERVICE_PORT=$(kubectl get service simple-calculator-service -o jsonpath='{.spec.ports[0].port}')
if [ -n "$SERVICE_IP" ] && [ "$SERVICE_IP" != "null" ]; then
echo "🎉 Calculator is ready!"
echo "🌐 Access your app at: http://$SERVICE_IP:$SERVICE_PORT"
else
echo "🎉 Calculator is ready!"
echo "🔗 Use port-forwarding to access: kubectl port-forward service/simple-calculator-service 8080:80"
echo "🌐 Then visit: http://localhost:8080"
fi
echo ""
echo "📊 Useful commands:"
echo " kubectl get pods"
echo " kubectl get services"
echo " kubectl logs -l app=simple-calculator"
echo " kubectl describe deployment simple-calculator"
echo ""
echo "🛑 To clean up:"
echo " kubectl delete -f k8s/"
echo " kind delete cluster --name kind"