Reorganize infrastructure as code and implement versioning schema

This commit is contained in:
Alphaeus Mote
2025-05-21 19:40:57 -04:00
parent 8d1a6dd188
commit 2db108aa6b
34 changed files with 4870 additions and 870 deletions
+14
View File
@@ -0,0 +1,14 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: ad-management-config
namespace: ad-management
data:
NODE_ENV: "production"
PORT: "5000"
BASE_URL: "https://ad-management.example.com"
DEFAULT_ADMIN_USERNAME: "admin"
DEFAULT_ADMIN_FULLNAME: "System Administrator"
DISABLE_REGISTRATION: "false"
POSTGRES_DB: "admgr"
POSTGRES_USER: "postgres"
+73
View File
@@ -0,0 +1,73 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: ad-management
namespace: ad-management
spec:
replicas: 2
selector:
matchLabels:
app: ad-management
template:
metadata:
labels:
app: ad-management
spec:
containers:
- name: activedirectorymanager
image: ActiveDirectoryManager:2025.05.21.1430
imagePullPolicy: Always
ports:
- containerPort: 5000
name: http
envFrom:
- configMapRef:
name: ad-management-config
- secretRef:
name: ad-management-secrets
env:
- name: REDIS_HOST
value: "redis"
- name: REDIS_PORT
value: "6379"
- name: POSTGRES_HOST
value: "postgres"
- name: POSTGRES_PORT
value: "5432"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "300m"
livenessProbe:
httpGet:
path: /api/health
port: http
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /api/health
port: http
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 1
---
apiVersion: v1
kind: Service
metadata:
name: ad-management
namespace: ad-management
spec:
selector:
app: ad-management
ports:
- port: 80
targetPort: 5000
name: http
type: ClusterIP
+26
View File
@@ -0,0 +1,26 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ad-management-ingress
namespace: ad-management
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
spec:
tls:
- hosts:
- ad-management.example.com
secretName: ad-management-tls
rules:
- host: ad-management.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: ad-management
port:
name: http
+13
View File
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: ad-management
resources:
- namespace.yaml
- configmap.yaml
- secrets.yaml
- postgres.yaml
- redis.yaml
- deployment.yaml
- ingress.yaml
+6
View File
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
name: ad-management
labels:
name: ad-management
+89
View File
@@ -0,0 +1,89 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
namespace: ad-management
spec:
serviceName: postgres
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:15-alpine
ports:
- containerPort: 5432
name: postgres
env:
- name: POSTGRES_DB
valueFrom:
configMapKeyRef:
name: ad-management-config
key: POSTGRES_DB
- name: POSTGRES_USER
valueFrom:
configMapKeyRef:
name: ad-management-config
key: POSTGRES_USER
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: ad-management-secrets
key: POSTGRES_PASSWORD
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "1Gi"
cpu: "500m"
livenessProbe:
exec:
command:
- pg_isready
- -U
- postgres
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
exec:
command:
- pg_isready
- -U
- postgres
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 1
volumeClaimTemplates:
- metadata:
name: postgres-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: ad-management
spec:
selector:
app: postgres
ports:
- port: 5432
targetPort: 5432
clusterIP: None # Headless service for StatefulSet
+71
View File
@@ -0,0 +1,71 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
namespace: ad-management
spec:
serviceName: redis
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:7-alpine
ports:
- containerPort: 6379
name: redis
volumeMounts:
- name: redis-data
mountPath: /data
resources:
requests:
memory: "128Mi"
cpu: "50m"
limits:
memory: "256Mi"
cpu: "200m"
livenessProbe:
exec:
command:
- redis-cli
- ping
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
exec:
command:
- redis-cli
- ping
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 1
volumeClaimTemplates:
- metadata:
name: redis-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
name: redis
namespace: ad-management
spec:
selector:
app: redis
ports:
- port: 6379
targetPort: 6379
clusterIP: None # Headless service for StatefulSet
+14
View File
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Secret
metadata:
name: ad-management-secrets
namespace: ad-management
type: Opaque
data:
# These are example values. In production, replace with your own base64-encoded secrets
# Example: echo -n "your-secret-value" | base64
JWT_SECRET: Y2hhbmdlLXRoaXMtaW4tcHJvZHVjdGlvbg==
SESSION_SECRET: Y2hhbmdlLXRoaXMtaW4tcHJvZHVjdGlvbg==
DEFAULT_ADMIN_PASSWORD: cGFzc3dvcmQ=
DEFAULT_ADMIN_EMAIL: YWRtaW5AZXhhbXBsZS5jb20=
POSTGRES_PASSWORD: cG9zdGdyZXM=
@@ -0,0 +1,40 @@
# PowerShell script to update the Kubernetes deployment with the current version
# Get the directory of this script
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$parentDir = Split-Path -Parent $scriptDir
# Read the version from version.txt
$versionFile = Join-Path $parentDir "version.txt"
if (-not (Test-Path $versionFile)) {
Write-Host "Error: version.txt not found at $versionFile" -ForegroundColor Red
exit 1
}
$version = Get-Content $versionFile -Raw
$version = $version.Trim()
Write-Host "Using version: $version" -ForegroundColor Cyan
# Update the deployment.yaml file
$deploymentFile = Join-Path $scriptDir "deployment.yaml"
if (-not (Test-Path $deploymentFile)) {
Write-Host "Error: deployment.yaml not found at $deploymentFile" -ForegroundColor Red
exit 1
}
# Read the deployment file
$content = Get-Content $deploymentFile -Raw
# Replace the image version
$pattern1 = 'image: ActiveDirectoryManager:[0-9]{4}\.[0-9]{2}\.[0-9]{2}\.[0-9]{4}'
$replacement1 = "image: ActiveDirectoryManager:$version"
$content = $content -replace $pattern1, $replacement1
$pattern2 = 'image: ActiveDirectoryManager:latest'
$replacement2 = "image: ActiveDirectoryManager:$version"
$content = $content -replace $pattern2, $replacement2
# Write the updated content back to the file
$content | Set-Content $deploymentFile
Write-Host "Updated deployment.yaml with version $version" -ForegroundColor Green
@@ -0,0 +1,36 @@
#!/bin/bash
# Script to update the Kubernetes deployment with the current version
# Get the directory of this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PARENT_DIR="$(dirname "$SCRIPT_DIR")"
# Read the version from version.txt
VERSION_FILE="$PARENT_DIR/version.txt"
if [ ! -f "$VERSION_FILE" ]; then
echo "Error: version.txt not found at $VERSION_FILE"
exit 1
fi
VERSION=$(cat "$VERSION_FILE" | tr -d '[:space:]')
echo "Using version: $VERSION"
# Update the deployment.yaml file
DEPLOYMENT_FILE="$SCRIPT_DIR/deployment.yaml"
if [ ! -f "$DEPLOYMENT_FILE" ]; then
echo "Error: deployment.yaml not found at $DEPLOYMENT_FILE"
exit 1
fi
# Use sed to replace the image version
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS requires a different sed syntax
sed -i '' "s|image: ActiveDirectoryManager:[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{4\}|image: ActiveDirectoryManager:$VERSION|g" "$DEPLOYMENT_FILE"
sed -i '' "s|image: ActiveDirectoryManager:latest|image: ActiveDirectoryManager:$VERSION|g" "$DEPLOYMENT_FILE"
else
# Linux
sed -i "s|image: ActiveDirectoryManager:[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{4\}|image: ActiveDirectoryManager:$VERSION|g" "$DEPLOYMENT_FILE"
sed -i "s|image: ActiveDirectoryManager:latest|image: ActiveDirectoryManager:$VERSION|g" "$DEPLOYMENT_FILE"
fi
echo "Updated deployment.yaml with version $VERSION"