feat: add trading platform K8s deployment infrastructure
- Add Helm chart with 19 templates (Deployments, Services, Ingress, ConfigMaps, Secrets, NetworkPolicy, cert-manager) - Add Dockerfiles for 4 microservices (dashboard, data-service, execute-service, news-service) - Add CI/CD workflows (build-test, build-push, deploy) - Add raw K8s manifests, per-service Helm charts, and deploy scripts - Add SOPS-encrypted secrets template and config - Configure deployment to customer1 namespace - Include infrastructure components: PostgreSQL, Redis, Kafka
This commit is contained in:
parent
af4cb3d321
commit
d079d1239f
115 changed files with 5917 additions and 0 deletions
141
trading-platform/deploy/scripts/deploy.sh
Executable file
141
trading-platform/deploy/scripts/deploy.sh
Executable file
|
|
@ -0,0 +1,141 @@
|
|||
#!/bin/bash
|
||||
# =============================================================================
|
||||
# Deploy Trading Platform to Kubernetes
|
||||
# =============================================================================
|
||||
#
|
||||
# Usage:
|
||||
# ./deploy/scripts/deploy.sh [staging|production] [tag]
|
||||
#
|
||||
# Examples:
|
||||
# ./deploy/scripts/deploy.sh staging latest
|
||||
# ./deploy/scripts/deploy.sh production v1.2.3
|
||||
#
|
||||
# Prerequisites:
|
||||
# - kubectl configured with cluster access
|
||||
# - Helm 3.x installed
|
||||
# - Docker images pushed to registry
|
||||
# - cert-manager installed in cluster (for TLS)
|
||||
# =============================================================================
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ENVIRONMENT="${1:-staging}"
|
||||
IMAGE_TAG="${2:-latest}"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||
|
||||
# Validate environment
|
||||
if [[ ! "$ENVIRONMENT" =~ ^(staging|production)$ ]]; then
|
||||
echo "ERROR: Environment must be 'staging' or 'production', got '$ENVIRONMENT'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set namespace and values file based on environment
|
||||
if [[ "$ENVIRONMENT" == "staging" ]]; then
|
||||
NAMESPACE="customer1-staging"
|
||||
VALUES_FILE="$PROJECT_ROOT/deploy/k8s/overlays/staging/kustomization.yaml"
|
||||
else
|
||||
NAMESPACE="customer1"
|
||||
VALUES_FILE="$PROJECT_ROOT/deploy/k8s/overlays/production/kustomization.yaml"
|
||||
fi
|
||||
|
||||
echo "========================================================"
|
||||
echo " Deploying Trading Platform to $ENVIRONMENT"
|
||||
echo " Image tag: $IMAGE_TAG"
|
||||
echo " Namespace: $NAMESPACE"
|
||||
echo "========================================================"
|
||||
|
||||
# Confirm cluster context
|
||||
CURRENT_CONTEXT=$(kubectl config current-context 2>/dev/null || echo "unknown")
|
||||
echo "Current kubectl context: $CURRENT_CONTEXT"
|
||||
read -r -p "Continue? (y/N) " -n 1
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Deployment cancelled."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install dependencies (optional)
|
||||
echo ""
|
||||
echo "Step 1/5: Checking prerequisites..."
|
||||
|
||||
# Check for Helm
|
||||
if ! command -v helm &>/dev/null; then
|
||||
echo "ERROR: helm is not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for kubectl
|
||||
if ! command -v kubectl &>/dev/null; then
|
||||
echo "ERROR: kubectl is not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check cluster connectivity
|
||||
if ! kubectl cluster-info &>/dev/null; then
|
||||
echo "ERROR: Cannot connect to Kubernetes cluster"
|
||||
exit 1
|
||||
fi
|
||||
echo " ✓ Kubernetes cluster is accessible"
|
||||
|
||||
# Create namespace if it doesn't exist
|
||||
kubectl create namespace "$NAMESPACE" --dry-run=client -o yaml | kubectl apply -f -
|
||||
echo " ✓ Namespace $NAMESPACE exists"
|
||||
|
||||
# Step 2: Deploy infrastructure (PostgreSQL, Redis, Kafka)
|
||||
echo ""
|
||||
echo "Step 2/5: Deploying infrastructure..."
|
||||
kubectl apply -f "$PROJECT_ROOT/deploy/k8s/base/namespace.yaml"
|
||||
kubectl apply -f "$PROJECT_ROOT/deploy/k8s/base/configmap.yaml"
|
||||
echo " ✓ ConfigMap applied"
|
||||
|
||||
# Step 3: Deploy services
|
||||
echo ""
|
||||
echo "Step 3/5: Deploying microservices..."
|
||||
|
||||
SERVICES=("execute-service" "data-service" "news-service" "api-gateway" "dashboard")
|
||||
|
||||
for service in "${SERVICES[@]}"; do
|
||||
echo " Deploying $service..."
|
||||
kubectl apply -f "$PROJECT_ROOT/deploy/k8s/base/${service}-deployment.yaml"
|
||||
kubectl apply -f "$PROJECT_ROOT/deploy/k8s/base/${service}-service.yaml"
|
||||
done
|
||||
|
||||
echo " ✓ All services deployed"
|
||||
|
||||
# Step 4: Deploy ingress and networking
|
||||
echo ""
|
||||
echo "Step 4/5: Configuring ingress and networking..."
|
||||
kubectl apply -f "$PROJECT_ROOT/deploy/k8s/base/ingress.yaml"
|
||||
echo " ✓ Ingress configured"
|
||||
|
||||
# Apply NetworkPolicies from security review
|
||||
if [[ -d "$PROJECT_ROOT/trading-platform/security/network-policies" ]]; then
|
||||
kubectl apply -f "$PROJECT_ROOT/trading-platform/security/network-policies/"
|
||||
echo " ✓ NetworkPolicies applied"
|
||||
fi
|
||||
|
||||
# Step 5: Wait for rollouts
|
||||
echo ""
|
||||
echo "Step 5/5: Waiting for deployments to stabilize..."
|
||||
|
||||
for service in "${SERVICES[@]}"; do
|
||||
echo " Waiting for $service..."
|
||||
if ! kubectl rollout status "deployment/${service}" -n "$NAMESPACE" --timeout=5m; then
|
||||
echo "WARNING: $service rollout timed out"
|
||||
echo " Check pods: kubectl get pods -n $NAMESPACE -l app=$service"
|
||||
echo " Check logs: kubectl logs -n $NAMESPACE -l app=$service --tail=100"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "========================================================"
|
||||
echo " Deployment complete! All services running."
|
||||
echo "========================================================"
|
||||
echo ""
|
||||
echo "Useful commands:"
|
||||
echo " kubectl get pods -n $NAMESPACE"
|
||||
echo " kubectl get svc -n $NAMESPACE"
|
||||
echo " kubectl get ingress -n $NAMESPACE"
|
||||
echo " kubectl logs -n $NAMESPACE -l app=$service -f"
|
||||
66
trading-platform/deploy/scripts/generate-mtls-certs.sh
Executable file
66
trading-platform/deploy/scripts/generate-mtls-certs.sh
Executable file
|
|
@ -0,0 +1,66 @@
|
|||
#!/bin/bash
|
||||
# =============================================================================
|
||||
# Manual mTLS certificate generation script (for dev/testing only)
|
||||
# =============================================================================
|
||||
# In production, use cert-manager (see k8s/base/cert-manager/).
|
||||
# This script generates self-signed certificates for local testing.
|
||||
#
|
||||
# Usage:
|
||||
# ./deploy/scripts/generate-mtls-certs.sh
|
||||
#
|
||||
# Output: deploy/mtls/
|
||||
# =============================================================================
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
OUTPUT_DIR="deploy/mtls"
|
||||
SERVICES=("execute-service" "data-service" "news-service" "api-gateway" "dashboard")
|
||||
DAYS_VALID=365
|
||||
|
||||
mkdir -p "$OUTPUT_DIR/ca" "$OUTPUT_DIR/certs"
|
||||
|
||||
# ── Generate Root CA ────────────────────────────────────────────────────────
|
||||
echo "Generating Root CA..."
|
||||
openssl genrsa -out "$OUTPUT_DIR/ca/ca.key" 4096 2>/dev/null
|
||||
openssl req -x509 -new -nodes \
|
||||
-key "$OUTPUT_DIR/ca/ca.key" \
|
||||
-sha256 \
|
||||
-days $DAYS_VALID \
|
||||
-out "$OUTPUT_DIR/ca/ca.crt" \
|
||||
-subj "/C=US/ST=California/O=TradingPlatform/CN=Trading Platform Root CA"
|
||||
|
||||
# ── Generate Service Certificates ────────────────────────────────────────────
|
||||
for SERVICE in "${SERVICES[@]}"; do
|
||||
echo "Generating certificate for $SERVICE..."
|
||||
|
||||
# Generate private key
|
||||
openssl genrsa \
|
||||
-out "$OUTPUT_DIR/certs/${SERVICE}.key" 2048 2>/dev/null
|
||||
|
||||
# Generate CSR
|
||||
openssl req -new \
|
||||
-key "$OUTPUT_DIR/certs/${SERVICE}.key" \
|
||||
-out "$OUTPUT_DIR/certs/${SERVICE}.csr" \
|
||||
-subj "/C=US/ST=California/O=TradingPlatform/CN=${SERVICE}.customer1.svc.cluster.local" \
|
||||
-addext "subjectAltName=DNS:${SERVICE},DNS:${SERVICE}.customer1,DNS:${SERVICE}.customer1.svc.cluster.local"
|
||||
|
||||
# Sign with CA
|
||||
openssl x509 -req \
|
||||
-in "$OUTPUT_DIR/certs/${SERVICE}.csr" \
|
||||
-CA "$OUTPUT_DIR/ca/ca.crt" \
|
||||
-CAkey "$OUTPUT_DIR/ca/ca.key" \
|
||||
-CAcreateserial \
|
||||
-out "$OUTPUT_DIR/certs/${SERVICE}.crt" \
|
||||
-days $DAYS_VALID \
|
||||
-sha256 \
|
||||
-extfile <(printf "subjectAltName=DNS:${SERVICE},DNS:${SERVICE}.customer1,DNS:${SERVICE}.customer1.svc.cluster.local")
|
||||
|
||||
# Clean up CSR
|
||||
rm "$OUTPUT_DIR/certs/${SERVICE}.csr"
|
||||
done
|
||||
|
||||
echo "Done! All certificates generated in $OUTPUT_DIR/certs/"
|
||||
echo "CA certificate: $OUTPUT_DIR/ca/ca.crt"
|
||||
echo ""
|
||||
echo "To verify a certificate:"
|
||||
echo " openssl verify -CAfile $OUTPUT_DIR/ca/ca.crt $OUTPUT_DIR/certs/<service>.crt"
|
||||
Loading…
Reference in a new issue