Initial commit: add .gitignore and README
This commit is contained in:
145
migration/migrate-to-k8s.sh
Executable file
145
migration/migrate-to-k8s.sh
Executable file
@@ -0,0 +1,145 @@
|
||||
#!/bin/bash
|
||||
# Script to help migrate projects to shared Kubernetes cluster
|
||||
|
||||
set -e
|
||||
|
||||
# Load shared libraries
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/../lib/init.sh"
|
||||
|
||||
PROJECT_NAME="${1:-}"
|
||||
|
||||
if [ -z "$PROJECT_NAME" ]; then
|
||||
log_heading "☸️ Kubernetes Migration Helper"
|
||||
echo ""
|
||||
echo "Usage: $0 <project-name>"
|
||||
echo ""
|
||||
echo "This script helps migrate a project to the shared Kubernetes cluster."
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate input
|
||||
validate_project_name "$PROJECT_NAME"
|
||||
|
||||
NAMESPACE="${PROJECT_NAME}"
|
||||
|
||||
log_heading "☸️ Migrating $PROJECT_NAME to shared Kubernetes cluster..."
|
||||
|
||||
# Create namespace using Terraform module or kubectl
|
||||
echo "📦 Creating namespace: $NAMESPACE"
|
||||
|
||||
cat > "/tmp/${PROJECT_NAME}-namespace.yaml" << EOF
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: ${NAMESPACE}
|
||||
labels:
|
||||
app: ${PROJECT_NAME}
|
||||
managed: terraform
|
||||
spec: {}
|
||||
EOF
|
||||
|
||||
# Create basic deployment template
|
||||
cat > "/tmp/${PROJECT_NAME}-deployment.yaml" << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: ${PROJECT_NAME}
|
||||
namespace: ${NAMESPACE}
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: ${PROJECT_NAME}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: ${PROJECT_NAME}
|
||||
spec:
|
||||
containers:
|
||||
- name: ${PROJECT_NAME}
|
||||
image: ${PROJECT_NAME}:latest
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
name: http
|
||||
resources:
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
cpu: "100m"
|
||||
limits:
|
||||
memory: "512Mi"
|
||||
cpu: "500m"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 8080
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /ready
|
||||
port: 8080
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
EOF
|
||||
|
||||
# Create service template
|
||||
cat > "/tmp/${PROJECT_NAME}-service.yaml" << EOF
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: ${PROJECT_NAME}
|
||||
namespace: ${NAMESPACE}
|
||||
spec:
|
||||
selector:
|
||||
app: ${PROJECT_NAME}
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 8080
|
||||
protocol: TCP
|
||||
name: http
|
||||
EOF
|
||||
|
||||
# Create ingress template
|
||||
cat > "/tmp/${PROJECT_NAME}-ingress.yaml" << EOF
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: ${PROJECT_NAME}
|
||||
namespace: ${NAMESPACE}
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: nginx
|
||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- ${PROJECT_NAME}.example.com
|
||||
secretName: ${PROJECT_NAME}-tls
|
||||
rules:
|
||||
- host: ${PROJECT_NAME}.example.com
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: ${PROJECT_NAME}
|
||||
port:
|
||||
number: 80
|
||||
EOF
|
||||
|
||||
log_success "Created migration templates:"
|
||||
log_info " - /tmp/${PROJECT_NAME}-namespace.yaml"
|
||||
log_info " - /tmp/${PROJECT_NAME}-deployment.yaml"
|
||||
log_info " - /tmp/${PROJECT_NAME}-service.yaml"
|
||||
log_info " - /tmp/${PROJECT_NAME}-ingress.yaml"
|
||||
echo ""
|
||||
log_step "Next steps:"
|
||||
log_info " 1. Review and customize templates"
|
||||
log_info " 2. Update image name and configuration"
|
||||
log_info " 3. Apply resources:"
|
||||
log_info " kubectl apply -f /tmp/${PROJECT_NAME}-*.yaml"
|
||||
echo ""
|
||||
log_info "📖 See docs/K8S_MIGRATION_GUIDE.md for detailed instructions"
|
||||
|
||||
Reference in New Issue
Block a user