198 lines
4.5 KiB
YAML
198 lines
4.5 KiB
YAML
---
|
|
# Namespace for testing
|
|
apiVersion: v1
|
|
kind: Namespace
|
|
metadata:
|
|
name: ha-test
|
|
|
|
---
|
|
# ConfigMap with application configuration
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: nginx-config
|
|
namespace: ha-test
|
|
data:
|
|
index.html: |
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>HA Cluster Test</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; margin: 40px; }
|
|
.info { background: #e7f3ff; padding: 20px; border-radius: 5px; margin: 10px 0; }
|
|
.hostname { color: #2196F3; font-weight: bold; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Kubernetes HA Cluster Test</h1>
|
|
<div class="info">
|
|
<p><strong>Pod Hostname:</strong> <span class="hostname" id="hostname"></span></p>
|
|
<p><strong>Timestamp:</strong> <span id="timestamp"></span></p>
|
|
<p><strong>Node IP:</strong> <span id="nodeip"></span></p>
|
|
</div>
|
|
<script>
|
|
document.getElementById('hostname').textContent = window.location.hostname;
|
|
document.getElementById('timestamp').textContent = new Date().toISOString();
|
|
// Node IP will be shown via environment variable injection
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|
|
---
|
|
# Deployment with multiple replicas for HA testing
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: ha-test-app
|
|
namespace: ha-test
|
|
labels:
|
|
app: ha-test-app
|
|
spec:
|
|
replicas: 6 # Deploy across multiple nodes
|
|
strategy:
|
|
type: RollingUpdate
|
|
rollingUpdate:
|
|
maxUnavailable: 1
|
|
maxSurge: 1
|
|
selector:
|
|
matchLabels:
|
|
app: ha-test-app
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: ha-test-app
|
|
spec:
|
|
# Anti-affinity to spread pods across nodes
|
|
affinity:
|
|
podAntiAffinity:
|
|
preferredDuringSchedulingIgnoredDuringExecution:
|
|
- weight: 100
|
|
podAffinityTerm:
|
|
labelSelector:
|
|
matchExpressions:
|
|
- key: app
|
|
operator: In
|
|
values:
|
|
- ha-test-app
|
|
topologyKey: kubernetes.io/hostname
|
|
containers:
|
|
- name: nginx
|
|
image: nginx:1.25-alpine
|
|
ports:
|
|
- containerPort: 80
|
|
name: http
|
|
env:
|
|
- name: NODE_NAME
|
|
valueFrom:
|
|
fieldRef:
|
|
fieldPath: spec.nodeName
|
|
- name: POD_NAME
|
|
valueFrom:
|
|
fieldRef:
|
|
fieldPath: metadata.name
|
|
- name: POD_IP
|
|
valueFrom:
|
|
fieldRef:
|
|
fieldPath: status.podIP
|
|
volumeMounts:
|
|
- name: nginx-config
|
|
mountPath: /usr/share/nginx/html
|
|
resources:
|
|
requests:
|
|
memory: "64Mi"
|
|
cpu: "50m"
|
|
limits:
|
|
memory: "128Mi"
|
|
cpu: "100m"
|
|
livenessProbe:
|
|
httpGet:
|
|
path: /
|
|
port: 80
|
|
initialDelaySeconds: 10
|
|
periodSeconds: 10
|
|
readinessProbe:
|
|
httpGet:
|
|
path: /
|
|
port: 80
|
|
initialDelaySeconds: 5
|
|
periodSeconds: 5
|
|
volumes:
|
|
- name: nginx-config
|
|
configMap:
|
|
name: nginx-config
|
|
|
|
---
|
|
# Service to expose the deployment
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: ha-test-service
|
|
namespace: ha-test
|
|
labels:
|
|
app: ha-test-app
|
|
spec:
|
|
selector:
|
|
app: ha-test-app
|
|
ports:
|
|
- port: 80
|
|
targetPort: 80
|
|
protocol: TCP
|
|
name: http
|
|
type: ClusterIP
|
|
|
|
---
|
|
# NodePort Service for external access (alternative to ingress)
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: ha-test-nodeport
|
|
namespace: ha-test
|
|
labels:
|
|
app: ha-test-app
|
|
spec:
|
|
selector:
|
|
app: ha-test-app
|
|
ports:
|
|
- port: 80
|
|
targetPort: 80
|
|
nodePort: 30080
|
|
protocol: TCP
|
|
name: http
|
|
type: NodePort
|
|
|
|
---
|
|
# HorizontalPodAutoscaler for testing scaling
|
|
apiVersion: autoscaling/v2
|
|
kind: HorizontalPodAutoscaler
|
|
metadata:
|
|
name: ha-test-hpa
|
|
namespace: ha-test
|
|
spec:
|
|
scaleTargetRef:
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
name: ha-test-app
|
|
minReplicas: 3
|
|
maxReplicas: 12
|
|
metrics:
|
|
- type: Resource
|
|
resource:
|
|
name: cpu
|
|
target:
|
|
type: Utilization
|
|
averageUtilization: 70
|
|
|
|
---
|
|
# PodDisruptionBudget for HA
|
|
apiVersion: policy/v1
|
|
kind: PodDisruptionBudget
|
|
metadata:
|
|
name: ha-test-pdb
|
|
namespace: ha-test
|
|
spec:
|
|
minAvailable: 2
|
|
selector:
|
|
matchLabels:
|
|
app: ha-test-app
|