add configs
This commit is contained in:
92
k8s/README.md
Normal file
92
k8s/README.md
Normal file
@@ -0,0 +1,92 @@
|
||||
# Kubernetes Deployment
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Kubernetes cluster (minikube, kind, or cloud provider)
|
||||
- kubectl configured
|
||||
- Docker images built and available
|
||||
|
||||
## Building Docker Images
|
||||
|
||||
```bash
|
||||
# Build Gateway image
|
||||
docker build -t liquidcode-tester-gateway:latest -f src/LiquidCode.Tester.Gateway/Dockerfile .
|
||||
|
||||
# Build C++ Worker image
|
||||
docker build -t liquidcode-tester-worker-cpp:latest -f src/LiquidCode.Tester.Worker/Dockerfile .
|
||||
```
|
||||
|
||||
## Deploying to Kubernetes
|
||||
|
||||
```bash
|
||||
# Create namespace
|
||||
kubectl apply -f k8s/namespace.yaml
|
||||
|
||||
# Apply ConfigMap
|
||||
kubectl apply -f k8s/configmap.yaml
|
||||
|
||||
# Deploy Worker (must be deployed first)
|
||||
kubectl apply -f k8s/worker-cpp-deployment.yaml
|
||||
|
||||
# Deploy Gateway
|
||||
kubectl apply -f k8s/gateway-deployment.yaml
|
||||
```
|
||||
|
||||
## Checking Status
|
||||
|
||||
```bash
|
||||
# Check all resources
|
||||
kubectl get all -n liquidcode-tester
|
||||
|
||||
# Check pods
|
||||
kubectl get pods -n liquidcode-tester
|
||||
|
||||
# Check services
|
||||
kubectl get services -n liquidcode-tester
|
||||
|
||||
# View logs
|
||||
kubectl logs -n liquidcode-tester -l app=gateway
|
||||
kubectl logs -n liquidcode-tester -l app=worker-cpp
|
||||
```
|
||||
|
||||
## Access the Gateway
|
||||
|
||||
```bash
|
||||
# Get the external IP (for LoadBalancer)
|
||||
kubectl get service liquidcode-tester-gateway -n liquidcode-tester
|
||||
|
||||
# For minikube
|
||||
minikube service liquidcode-tester-gateway -n liquidcode-tester
|
||||
|
||||
# Port forward (alternative)
|
||||
kubectl port-forward -n liquidcode-tester service/liquidcode-tester-gateway 8080:80
|
||||
```
|
||||
|
||||
## Scaling Workers
|
||||
|
||||
```bash
|
||||
# Scale C++ workers
|
||||
kubectl scale deployment liquidcode-tester-worker-cpp -n liquidcode-tester --replicas=5
|
||||
```
|
||||
|
||||
## Cleanup
|
||||
|
||||
```bash
|
||||
# Delete all resources
|
||||
kubectl delete namespace liquidcode-tester
|
||||
```
|
||||
|
||||
## Production Considerations
|
||||
|
||||
1. **Image Registry**: Push images to a container registry (Docker Hub, GCR, ECR, etc.)
|
||||
2. **Resource Limits**: Adjust CPU/Memory limits based on workload
|
||||
3. **Persistent Storage**: Add PersistentVolumes for package storage if needed
|
||||
4. **Monitoring**: Add Prometheus/Grafana for metrics
|
||||
5. **Logging**: Configure centralized logging (ELK, Loki, etc.)
|
||||
6. **Security**:
|
||||
- Use NetworkPolicies to restrict traffic
|
||||
- Enable Pod Security Standards
|
||||
- Use secrets for sensitive data
|
||||
- Consider using a service mesh (Istio, Linkerd)
|
||||
7. **Autoscaling**: Configure HorizontalPodAutoscaler for workers
|
||||
8. **Ingress**: Use Ingress controller instead of LoadBalancer for production
|
||||
37
k8s/configmap.yaml
Normal file
37
k8s/configmap.yaml
Normal file
@@ -0,0 +1,37 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: liquidcode-tester-config
|
||||
namespace: liquidcode-tester
|
||||
data:
|
||||
gateway.appsettings.json: |
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"PackageDownloadDirectory": "/tmp/packages",
|
||||
"Workers": {
|
||||
"Cpp": "http://liquidcode-tester-worker-cpp:8080",
|
||||
"Java": "http://liquidcode-tester-worker-java:8080",
|
||||
"Kotlin": "http://liquidcode-tester-worker-kotlin:8080",
|
||||
"CSharp": "http://liquidcode-tester-worker-csharp:8080"
|
||||
}
|
||||
}
|
||||
worker.appsettings.json: |
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Cpp": {
|
||||
"Compiler": "g++",
|
||||
"CompilerFlags": "-O2 -std=c++17 -Wall"
|
||||
}
|
||||
}
|
||||
63
k8s/gateway-deployment.yaml
Normal file
63
k8s/gateway-deployment.yaml
Normal file
@@ -0,0 +1,63 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: liquidcode-tester-gateway
|
||||
namespace: liquidcode-tester
|
||||
labels:
|
||||
app: gateway
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: gateway
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: gateway
|
||||
spec:
|
||||
containers:
|
||||
- name: gateway
|
||||
image: liquidcode-tester-gateway:latest
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
name: http
|
||||
env:
|
||||
- name: ASPNETCORE_ENVIRONMENT
|
||||
value: "Production"
|
||||
- name: Workers__Cpp
|
||||
value: "http://liquidcode-tester-worker-cpp:8080"
|
||||
resources:
|
||||
requests:
|
||||
memory: "128Mi"
|
||||
cpu: "100m"
|
||||
limits:
|
||||
memory: "512Mi"
|
||||
cpu: "500m"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api/tester/health
|
||||
port: 8080
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 30
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /api/tester/health
|
||||
port: 8080
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 10
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: liquidcode-tester-gateway
|
||||
namespace: liquidcode-tester
|
||||
spec:
|
||||
type: LoadBalancer
|
||||
selector:
|
||||
app: gateway
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 8080
|
||||
protocol: TCP
|
||||
name: http
|
||||
4
k8s/namespace.yaml
Normal file
4
k8s/namespace.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: liquidcode-tester
|
||||
82
k8s/worker-cpp-deployment.yaml
Normal file
82
k8s/worker-cpp-deployment.yaml
Normal file
@@ -0,0 +1,82 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: liquidcode-tester-worker-cpp
|
||||
namespace: liquidcode-tester
|
||||
labels:
|
||||
app: worker-cpp
|
||||
language: cpp
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: worker-cpp
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: worker-cpp
|
||||
language: cpp
|
||||
spec:
|
||||
containers:
|
||||
- name: worker-cpp
|
||||
image: liquidcode-tester-worker-cpp:latest
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
name: http
|
||||
env:
|
||||
- name: ASPNETCORE_ENVIRONMENT
|
||||
value: "Production"
|
||||
- name: Cpp__Compiler
|
||||
value: "g++"
|
||||
- name: Cpp__CompilerFlags
|
||||
value: "-O2 -std=c++17 -Wall"
|
||||
resources:
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
cpu: "200m"
|
||||
limits:
|
||||
memory: "2Gi"
|
||||
cpu: "1000m"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api/test/health
|
||||
port: 8080
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 30
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /api/test/health
|
||||
port: 8080
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 10
|
||||
# Security context for isolation
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
runAsNonRoot: true
|
||||
runAsUser: 1000
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
readOnlyRootFilesystem: false
|
||||
volumeMounts:
|
||||
- name: tmp
|
||||
mountPath: /tmp
|
||||
volumes:
|
||||
- name: tmp
|
||||
emptyDir: {}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: liquidcode-tester-worker-cpp
|
||||
namespace: liquidcode-tester
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: worker-cpp
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
protocol: TCP
|
||||
name: http
|
||||
Reference in New Issue
Block a user