-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtaskflow-setup-k8s.sh
More file actions
183 lines (159 loc) · 4.95 KB
/
taskflow-setup-k8s.sh
File metadata and controls
183 lines (159 loc) · 4.95 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
#!/bin/bash
# TaskFlow Kubernetes Setup Script
# Run this to deploy TaskFlow to minikube manually
set -e
NAMESPACE="taskflow"
K8S_DIR="/usr/share/taskflow-cli/k8s"
echo "TaskFlow Kubernetes Setup"
echo "=============================="
echo ""
# Check if commands exist
command_exists() {
command -v "$1" >/dev/null 2>&1
}
if ! command_exists minikube; then
echo "minikube not found"
echo "Install: https://minikube.sigs.k8s.io/docs/start/"
exit 1
fi
if ! command_exists kubectl; then
echo "kubectl not found"
echo "Install: https://kubernetes.io/docs/tasks/tools/"
exit 1
fi
if ! command_exists docker; then
echo "docker not found"
echo "Install: https://docs.docker.com/get-docker/"
exit 1
fi
# Check if minikube is running
echo "Checking minikube status..."
if ! minikube status >/dev/null 2>&1; then
echo "Starting minikube (this may take 2-3 minutes)..."
minikube start --driver=docker || {
echo "Failed to start minikube"
echo "Try: minikube delete && minikube start"
exit 1
}
fi
echo "✓ Minikube is running"
# Create namespace
echo "Creating namespace: $NAMESPACE"
kubectl create namespace $NAMESPACE 2>/dev/null || echo " (namespace already exists)"
# Generate secrets if not exists
SECRETS_FILE="$K8S_DIR/01-secrets.yaml"
if [ ! -f "$SECRETS_FILE" ]; then
echo "Generating secrets..."
# Generate generic secrets
sudo bash -c "cat > '$SECRETS_FILE' << EOF
apiVersion: v1
kind: Secret
metadata:
name: taskflow-db-secret
namespace: $NAMESPACE
type: Opaque
stringData:
POSTGRES_DB: \"taskflow_db\"
POSTGRES_USER: \"postgres\"
POSTGRES_PASSWORD: \"password\"
DATABASE_URL: \"postgresql://postgres:password@taskflow-pgbouncer:6432/taskflow_db\"
---
apiVersion: v1
kind: Secret
metadata:
name: taskflow-redis-secret
namespace: $NAMESPACE
type: Opaque
stringData:
REDIS_PASSWORD: \"\" # No password for KEDA compatibility
REDIS_HOST_HIGH: \"redis-high\"
REDIS_PORT_HIGH: \"6379\"
REDIS_HOST_LOW: \"redis-low\"
REDIS_PORT_LOW: \"6379\"
---
apiVersion: v1
kind: Secret
metadata:
name: taskflow-app-secret
namespace: $NAMESPACE
type: Opaque
stringData:
SECRET_KEY: \"test_secret_key_for_ci_only\"
ALGORITHM: \"HS256\"
ACCESS_TOKEN_EXPIRE_MINUTES: \"60\"
EOF"
echo "✓ Secrets generated"
else
echo "✓ Using existing secrets"
fi
# Apply Secrets
echo "Applying secrets..."
kubectl apply -f "$SECRETS_FILE" -n $NAMESPACE
# Apply ConfigMaps
echo "Applying ConfigMaps..."
if [ -f "$K8S_DIR/02-configmaps.yaml" ]; then
kubectl apply -f "$K8S_DIR/02-configmaps.yaml" -n $NAMESPACE
else
echo "Warning: 02-configmaps.yaml not found!"
fi
# Apply infrastructure (database, redis)
echo "Deploying infrastructure (postgres, redis)..."
kubectl apply -f "$K8S_DIR/infrastructure/" -n $NAMESPACE
# Wait for infrastructure
echo "Waiting for infrastructure to be ready (10 seconds)..."
sleep 10
# Apply applications (api, worker, queue-manager)
echo "Deploying applications (api, worker, queue-manager)..."
kubectl apply -f "$K8S_DIR/apps/" -n $NAMESPACE
# Wait for API to be ready
echo "Waiting for API to be ready (this may take 2-3 minutes)..."
kubectl wait --for=condition=ready pod -l app=taskflow-api -n $NAMESPACE --timeout=300s || {
echo ""
echo "Timeout waiting for API pod"
echo "Check status with:"
echo " kubectl get pods -n $NAMESPACE"
echo " kubectl logs -n $NAMESPACE -l app=taskflow-api"
echo ""
}
# Setup port forwarding as systemd service
echo "Setting up port forwarding service..."
# Detect the real user (who ran sudo)
REAL_USER=${SUDO_USER:-$USER}
USER_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6)
sudo bash -c "cat > /etc/systemd/system/taskflow-port-forward.service << SERVICEEOF
[Unit]
Description=TaskFlow API Port Forward
After=network.target
[Service]
Type=simple
User=$REAL_USER
Environment=KUBECONFIG=$USER_HOME/.kube/config
ExecStart=/usr/bin/kubectl port-forward -n taskflow service/taskflow-api 8080:80
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
SERVICEEOF"
sudo systemctl daemon-reload
sudo systemctl enable taskflow-port-forward.service
sudo systemctl restart taskflow-port-forward.service
echo ""
echo "TaskFlow deployed successfully!"
echo ""
echo "API is accessible at: http://localhost:8080"
echo ""
echo "Quick Start:"
echo " taskflow # Start interactive CLI"
echo " taskflow register # Create an account"
echo " taskflow login # Login"
echo ""
echo "Management Commands:"
echo " kubectl get pods -n $NAMESPACE # Check pod status"
echo " kubectl logs -n $NAMESPACE -l app=taskflow-api # View API logs"
echo " sudo systemctl status taskflow-port-forward # Check port forwarding"
echo " sudo systemctl stop taskflow-port-forward # Stop port forwarding"
echo ""
echo "Troubleshooting:"
echo " kubectl describe pods -n $NAMESPACE # Detailed pod info"
echo " minikube dashboard # Open Kubernetes dashboard"
echo ""