mirror of
https://github.com/ghndrx/k8s-game-2048.git
synced 2026-02-10 06:45:07 +00:00
Initial commit: 2048 game with Knative and Kourier deployment
- Complete 2048 game implementation with responsive design - Knative Serving manifests for dev/staging/prod environments - Scale-to-zero configuration with environment-specific settings - Custom domain mapping for wa.darknex.us subdomains - GitHub Actions workflows for CI/CD - Docker container with nginx and health checks - Setup scripts for Knative and Kourier installation - GHCR integration for container registry
This commit is contained in:
87
scripts/deploy.sh
Executable file
87
scripts/deploy.sh
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Deployment script for 2048 game environments
|
||||
# Usage: ./deploy.sh [dev|staging|prod] [image-tag]
|
||||
|
||||
set -e
|
||||
|
||||
ENVIRONMENT=${1:-dev}
|
||||
IMAGE_TAG=${2:-latest}
|
||||
REGISTRY="ghcr.io/ghndrx/k8s-game-2048"
|
||||
|
||||
echo "🚀 Deploying 2048 game to $ENVIRONMENT environment..."
|
||||
|
||||
# Validate environment
|
||||
case $ENVIRONMENT in
|
||||
dev|staging|prod)
|
||||
echo "✅ Valid environment: $ENVIRONMENT"
|
||||
;;
|
||||
*)
|
||||
echo "❌ Invalid environment. Use: dev, staging, or prod"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Check if kubectl is available
|
||||
if ! command -v kubectl &> /dev/null; then
|
||||
echo "❌ kubectl is not installed. Please install kubectl first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if cluster is accessible
|
||||
if ! kubectl cluster-info &> /dev/null; then
|
||||
echo "❌ Cannot access Kubernetes cluster. Please check your kubeconfig."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Update image tag in manifests
|
||||
echo "🔧 Updating image tag to $IMAGE_TAG..."
|
||||
if [ "$ENVIRONMENT" = "dev" ]; then
|
||||
sed -i.bak "s|your-registry/game-2048:latest|$REGISTRY:$IMAGE_TAG|g" manifests/dev/service.yml
|
||||
elif [ "$ENVIRONMENT" = "staging" ]; then
|
||||
sed -i.bak "s|your-registry/game-2048:staging|$REGISTRY:$IMAGE_TAG|g" manifests/staging/service.yml
|
||||
else
|
||||
sed -i.bak "s|your-registry/game-2048:v1.0.0|$REGISTRY:$IMAGE_TAG|g" manifests/prod/service.yml
|
||||
fi
|
||||
|
||||
# Deploy to the specified environment
|
||||
echo "📦 Deploying to $ENVIRONMENT..."
|
||||
kubectl apply -f manifests/$ENVIRONMENT/
|
||||
|
||||
# Wait for deployment to be ready
|
||||
echo "⏳ Waiting for deployment to be ready..."
|
||||
kubectl wait --for=condition=Ready ksvc/game-2048-$ENVIRONMENT -n game-2048-$ENVIRONMENT --timeout=300s
|
||||
|
||||
# Get service details
|
||||
echo "✅ Deployment completed!"
|
||||
echo ""
|
||||
echo "🔍 Service details:"
|
||||
kubectl get ksvc game-2048-$ENVIRONMENT -n game-2048-$ENVIRONMENT -o wide
|
||||
|
||||
echo ""
|
||||
echo "🌐 Service URL:"
|
||||
kubectl get ksvc game-2048-$ENVIRONMENT -n game-2048-$ENVIRONMENT -o jsonpath='{.status.url}'
|
||||
echo ""
|
||||
|
||||
echo ""
|
||||
echo "🎯 Custom domain:"
|
||||
case $ENVIRONMENT in
|
||||
dev)
|
||||
echo "https://2048-dev.wa.darknex.us"
|
||||
;;
|
||||
staging)
|
||||
echo "https://2048-staging.wa.darknex.us"
|
||||
;;
|
||||
prod)
|
||||
echo "https://2048.wa.darknex.us"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Restore original manifests
|
||||
echo "🔄 Restoring original manifests..."
|
||||
if [ -f "manifests/$ENVIRONMENT/service.yml.bak" ]; then
|
||||
mv manifests/$ENVIRONMENT/service.yml.bak manifests/$ENVIRONMENT/service.yml
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "🎮 Game deployed successfully! You can now access it at the custom domain."
|
||||
58
scripts/setup-knative.sh
Executable file
58
scripts/setup-knative.sh
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Setup script for Knative Serving installation
|
||||
# This script installs Knative Serving on a Kubernetes cluster
|
||||
|
||||
set -e
|
||||
|
||||
echo "🚀 Setting up Knative Serving..."
|
||||
|
||||
# Check if kubectl is available
|
||||
if ! command -v kubectl &> /dev/null; then
|
||||
echo "❌ kubectl is not installed. Please install kubectl first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if cluster is accessible
|
||||
if ! kubectl cluster-info &> /dev/null; then
|
||||
echo "❌ Cannot access Kubernetes cluster. Please check your kubeconfig."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install Knative Serving CRDs
|
||||
echo "📦 Installing Knative Serving CRDs..."
|
||||
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.12.0/serving-crds.yaml
|
||||
|
||||
# Wait for CRDs to be established
|
||||
echo "⏳ Waiting for CRDs to be established..."
|
||||
kubectl wait --for condition=established --timeout=120s crd/configurations.serving.knative.dev
|
||||
kubectl wait --for condition=established --timeout=120s crd/revisions.serving.knative.dev
|
||||
kubectl wait --for condition=established --timeout=120s crd/routes.serving.knative.dev
|
||||
kubectl wait --for condition=established --timeout=120s crd/services.serving.knative.dev
|
||||
|
||||
# Install Knative Serving core
|
||||
echo "📦 Installing Knative Serving core..."
|
||||
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.12.0/serving-core.yaml
|
||||
|
||||
# Wait for Knative Serving to be ready
|
||||
echo "⏳ Waiting for Knative Serving to be ready..."
|
||||
kubectl wait --for=condition=Ready pod -l app=controller -n knative-serving --timeout=300s
|
||||
kubectl wait --for=condition=Ready pod -l app=webhook -n knative-serving --timeout=300s
|
||||
|
||||
# Install Knative Serving HPA (Horizontal Pod Autoscaler)
|
||||
echo "📦 Installing Knative Serving HPA..."
|
||||
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.12.0/serving-hpa.yaml
|
||||
|
||||
# Configure domain
|
||||
echo "🌐 Configuring domain..."
|
||||
kubectl patch configmap/config-domain \
|
||||
--namespace knative-serving \
|
||||
--type merge \
|
||||
--patch '{"data":{"wa.darknex.us":""}}'
|
||||
|
||||
echo "✅ Knative Serving installation completed!"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Install Kourier as the networking layer: ./setup-kourier.sh"
|
||||
echo "2. Configure DNS to point your domain to the Kourier LoadBalancer"
|
||||
echo "3. Deploy your applications using the manifests in this repository"
|
||||
109
scripts/setup-kourier.sh
Executable file
109
scripts/setup-kourier.sh
Executable file
@@ -0,0 +1,109 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Setup script for Kourier networking layer
|
||||
# This script installs Kourier as the Knative networking layer
|
||||
|
||||
set -e
|
||||
|
||||
echo "🚀 Setting up Kourier networking layer..."
|
||||
|
||||
# Check if kubectl is available
|
||||
if ! command -v kubectl &> /dev/null; then
|
||||
echo "❌ kubectl is not installed. Please install kubectl first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if cluster is accessible
|
||||
if ! kubectl cluster-info &> /dev/null; then
|
||||
echo "❌ Cannot access Kubernetes cluster. Please check your kubeconfig."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if Knative Serving is installed
|
||||
if ! kubectl get namespace knative-serving &> /dev/null; then
|
||||
echo "❌ Knative Serving is not installed. Please run ./setup-knative.sh first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install Kourier
|
||||
echo "📦 Installing Kourier..."
|
||||
kubectl apply -f https://github.com/knative/net-kourier/releases/download/knative-v1.12.0/kourier.yaml
|
||||
|
||||
# Wait for Kourier to be ready
|
||||
echo "⏳ Waiting for Kourier to be ready..."
|
||||
kubectl wait --for=condition=Ready pod -l app=3scale-kourier-gateway -n kourier-system --timeout=300s
|
||||
|
||||
# Configure Knative to use Kourier
|
||||
echo "🔧 Configuring Knative to use Kourier..."
|
||||
kubectl patch configmap/config-network \
|
||||
--namespace knative-serving \
|
||||
--type merge \
|
||||
--patch '{"data":{"ingress-class":"kourier.ingress.networking.knative.dev"}}'
|
||||
|
||||
# Get the external IP of Kourier
|
||||
echo "🔍 Getting Kourier LoadBalancer details..."
|
||||
kubectl get svc kourier -n kourier-system
|
||||
|
||||
# Configure auto-TLS (optional)
|
||||
echo "🔐 Configuring auto-TLS..."
|
||||
kubectl patch configmap/config-network \
|
||||
--namespace knative-serving \
|
||||
--type merge \
|
||||
--patch '{"data":{"autoTLS":"Enabled","httpProtocol":"Redirected"}}'
|
||||
|
||||
# Install cert-manager for TLS (optional but recommended)
|
||||
echo "📦 Installing cert-manager for TLS..."
|
||||
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.0/cert-manager.yaml
|
||||
|
||||
# Wait for cert-manager to be ready
|
||||
echo "⏳ Waiting for cert-manager to be ready..."
|
||||
kubectl wait --for=condition=Ready pod -l app=cert-manager -n cert-manager --timeout=300s
|
||||
kubectl wait --for=condition=Ready pod -l app=cainjector -n cert-manager --timeout=300s
|
||||
kubectl wait --for=condition=Ready pod -l app=webhook -n cert-manager --timeout=300s
|
||||
|
||||
# Install Knative cert-manager integration
|
||||
echo "📦 Installing Knative cert-manager integration..."
|
||||
kubectl apply -f https://github.com/knative/net-certmanager/releases/download/knative-v1.12.0/release.yaml
|
||||
|
||||
# Create ClusterIssuer for Let's Encrypt
|
||||
echo "🔐 Creating Let's Encrypt ClusterIssuer..."
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: cert-manager.io/v1
|
||||
kind: ClusterIssuer
|
||||
metadata:
|
||||
name: letsencrypt-prod
|
||||
spec:
|
||||
acme:
|
||||
server: https://acme-v02.api.letsencrypt.org/directory
|
||||
email: admin@darknex.us
|
||||
privateKeySecretRef:
|
||||
name: letsencrypt-prod
|
||||
solvers:
|
||||
- http01:
|
||||
ingress:
|
||||
class: kourier.ingress.networking.knative.dev
|
||||
EOF
|
||||
|
||||
# Configure Knative to use the ClusterIssuer
|
||||
echo "🔧 Configuring Knative to use cert-manager..."
|
||||
kubectl patch configmap/config-certmanager \
|
||||
--namespace knative-serving \
|
||||
--type merge \
|
||||
--patch '{"data":{"issuerRef":"kind: ClusterIssuer\nname: letsencrypt-prod"}}'
|
||||
|
||||
echo "✅ Kourier setup completed!"
|
||||
echo ""
|
||||
echo "🔍 Kourier LoadBalancer service details:"
|
||||
kubectl get svc kourier -n kourier-system -o wide
|
||||
echo ""
|
||||
echo "📋 Next steps:"
|
||||
echo "1. Configure your DNS to point the following domains to the LoadBalancer IP:"
|
||||
echo " - 2048-dev.wa.darknex.us"
|
||||
echo " - 2048-staging.wa.darknex.us"
|
||||
echo " - 2048.wa.darknex.us"
|
||||
echo " - *.wa.darknex.us (wildcard)"
|
||||
echo ""
|
||||
echo "2. Deploy your applications:"
|
||||
echo " kubectl apply -f manifests/dev/"
|
||||
echo " kubectl apply -f manifests/staging/"
|
||||
echo " kubectl apply -f manifests/prod/"
|
||||
Reference in New Issue
Block a user