Skip to content

Commit dbd47fe

Browse files
committed
update: refine Kubernetes deployment configs and scripts
1 parent 43fc13e commit dbd47fe

File tree

6 files changed

+226
-5
lines changed

6 files changed

+226
-5
lines changed

k8s/00-secrets.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: Secret
44
metadata:
55
name: netpulse-secrets
6+
namespace: netpulse
67
type: Opaque
78
stringData:
89
# IMPORTANT: Replace these placeholder passwords with secure values before deploying to production

k8s/01-redis.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: Service
44
metadata:
55
name: redis-nodes
6+
namespace: netpulse
67
labels: {app: redis}
78
spec:
89
clusterIP: None # Headless Service
@@ -17,6 +18,7 @@ apiVersion: apps/v1
1718
kind: StatefulSet
1819
metadata:
1920
name: redis-nodes
21+
namespace: netpulse
2022
spec:
2123
serviceName: redis-nodes
2224
replicas: 3 # redis-0 is initial master
@@ -89,6 +91,7 @@ apiVersion: v1
8991
kind: Service
9092
metadata:
9193
name: redis-sentinel
94+
namespace: netpulse
9295
labels: {app: redis-sentinel}
9396
spec:
9497
ports:
@@ -101,6 +104,7 @@ apiVersion: apps/v1
101104
kind: StatefulSet
102105
metadata:
103106
name: redis-sentinel
107+
namespace: netpulse
104108
spec:
105109
serviceName: redis-sentinel
106110
replicas: 3
@@ -173,6 +177,7 @@ apiVersion: policy/v1
173177
kind: PodDisruptionBudget
174178
metadata:
175179
name: pdb-redis
180+
namespace: netpulse
176181
spec:
177182
minAvailable: 2
178183
selector:
@@ -183,6 +188,7 @@ apiVersion: policy/v1
183188
kind: PodDisruptionBudget
184189
metadata:
185190
name: pdb-redis-sentinel
191+
namespace: netpulse
186192
spec:
187193
minAvailable: 2
188194
selector:

k8s/02-netpulse.yaml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ apiVersion: v1
55
kind: ConfigMap
66
metadata:
77
name: netpulse-config
8+
namespace: netpulse
89
labels:
910
app: netpulse
1011
component: shared
@@ -26,6 +27,7 @@ apiVersion: apps/v1
2627
kind: Deployment
2728
metadata:
2829
name: netpulse-controller
30+
namespace: netpulse
2931
spec:
3032
replicas: 3
3133
selector:
@@ -42,6 +44,13 @@ spec:
4244
- name: controller
4345
image: localhost/netpulse-controller:latest
4446
imagePullPolicy: IfNotPresent
47+
resources:
48+
requests:
49+
memory: "4Gi"
50+
cpu: "2000m"
51+
limits:
52+
memory: "8Gi"
53+
cpu: "8000m"
4554
envFrom:
4655
- configMapRef:
4756
name: netpulse-config
@@ -69,8 +78,9 @@ apiVersion: apps/v1
6978
kind: Deployment
7079
metadata:
7180
name: netpulse-node-worker
81+
namespace: netpulse
7282
spec:
73-
replicas: 3
83+
replicas: 6
7484
selector:
7585
matchLabels:
7686
app: netpulse
@@ -85,6 +95,13 @@ spec:
8595
- name: node-worker
8696
image: localhost/netpulse-node-worker:latest
8797
imagePullPolicy: IfNotPresent
98+
resources:
99+
requests:
100+
memory: "2Gi"
101+
cpu: "1000m"
102+
limits:
103+
memory: "4Gi"
104+
cpu: "4000m"
88105
envFrom:
89106
- configMapRef:
90107
name: netpulse-config
@@ -110,8 +127,9 @@ apiVersion: apps/v1
110127
kind: Deployment
111128
metadata:
112129
name: netpulse-fifo-worker
130+
namespace: netpulse
113131
spec:
114-
replicas: 3
132+
replicas: 6
115133
selector:
116134
matchLabels:
117135
app: netpulse
@@ -126,6 +144,13 @@ spec:
126144
- name: fifo-worker
127145
image: localhost/netpulse-fifo-worker:latest
128146
imagePullPolicy: IfNotPresent
147+
resources:
148+
requests:
149+
memory: "2Gi"
150+
cpu: "1000m"
151+
limits:
152+
memory: "4Gi"
153+
cpu: "4000m"
129154
envFrom:
130155
- configMapRef:
131156
name: netpulse-config
@@ -151,6 +176,7 @@ apiVersion: v1
151176
kind: Service
152177
metadata:
153178
name: netpulse
179+
namespace: netpulse
154180
spec:
155181
selector:
156182
app: netpulse

k8s/03-ingress.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ apiVersion: networking.k8s.io/v1
33
kind: Ingress
44
metadata:
55
name: netpulse-ingress
6-
namespace: default
6+
namespace: netpulse
77
annotations:
88
nginx.ingress.kubernetes.io/rewrite-target: /
99
spec:
1010
ingressClassName: nginx
1111
rules:
12-
- host: netpulse.local
13-
http:
12+
- http:
1413
paths:
1514
- path: /
1615
pathType: Prefix

k8s/04-nodeport.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 04-nodeport/nodeport.yaml
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: netpulse-nodeport
6+
namespace: netpulse
7+
labels:
8+
app: netpulse
9+
spec:
10+
type: NodePort
11+
ports:
12+
- port: 9000
13+
targetPort: 9000
14+
nodePort: 30090
15+
protocol: TCP
16+
name: http
17+
selector:
18+
app: netpulse
19+
component: controller

scripts/k8s_setup_secrets.sh

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#!/bin/bash
2+
3+
# NetPulse Kubernetes Secrets Setup Script
4+
5+
set -e
6+
7+
COLOR_RED='\033[0;31m'
8+
COLOR_GREEN='\033[0;32m'
9+
COLOR_YELLOW='\033[1;33m'
10+
COLOR_BLUE='\033[0;34m'
11+
COLOR_NC='\033[0m' # No Color
12+
13+
print_status() {
14+
echo -e "${COLOR_BLUE}[INFO]${COLOR_NC} $1"
15+
}
16+
17+
print_success() {
18+
echo -e "${COLOR_GREEN}[SUCCESS]${COLOR_NC} $1"
19+
}
20+
21+
print_warning() {
22+
echo -e "${COLOR_YELLOW}[WARNING]${COLOR_NC} $1"
23+
}
24+
25+
print_error() {
26+
echo -e "${COLOR_RED}[ERROR]${COLOR_NC} $1"
27+
}
28+
29+
generate_secure_values() {
30+
print_status "Generating secure values for Kubernetes secrets..."
31+
32+
local redis_password=$(openssl rand -base64 32 | tr -d "=+/" | cut -c1-25)
33+
local api_key="np_$(openssl rand -hex 32)"
34+
35+
# Create deployment secrets file (not in git)
36+
cat > k8s/00-secrets-deploy.yaml << SECRETSEOF
37+
# 00-secrets/netpulse-secrets.yaml
38+
# Generated on $(date) - DO NOT commit to version control
39+
apiVersion: v1
40+
kind: Secret
41+
metadata:
42+
name: netpulse-secrets
43+
namespace: netpulse
44+
type: Opaque
45+
stringData:
46+
# Generated secure passwords - DO NOT commit to version control
47+
password: "$redis_password"
48+
api-key: "$api_key"
49+
SECRETSEOF
50+
51+
print_success "Secure secrets generated in k8s/00-secrets-deploy.yaml!"
52+
print_warning "Your API Key: $api_key"
53+
print_warning "Your Redis Password: $redis_password"
54+
print_warning "Please save these credentials securely!"
55+
print_status "Use: kubectl apply -f k8s/00-secrets-deploy.yaml"
56+
}
57+
58+
apply_secrets() {
59+
print_status "Applying secrets to Kubernetes cluster..."
60+
61+
# Check for deploy file first, then fall back to original
62+
local secrets_file=""
63+
if [ -f "k8s/00-secrets-deploy.yaml" ]; then
64+
secrets_file="k8s/00-secrets-deploy.yaml"
65+
print_status "Using generated secrets file: $secrets_file"
66+
elif [ -f "k8s/00-secrets.yaml" ]; then
67+
secrets_file="k8s/00-secrets.yaml"
68+
print_warning "Using original secrets file: $secrets_file"
69+
print_warning "Make sure you have updated the placeholder passwords!"
70+
else
71+
print_error "No secrets file found. Run 'generate' first or ensure k8s/00-secrets.yaml exists."
72+
return 1
73+
fi
74+
75+
kubectl apply -f "$secrets_file"
76+
77+
print_success "Secrets applied to Kubernetes cluster!"
78+
79+
# Verify secrets were created
80+
if kubectl get secret netpulse-secrets >/dev/null 2>&1; then
81+
print_success "Secret 'netpulse-secrets' created successfully"
82+
else
83+
print_error "Failed to create secret 'netpulse-secrets'"
84+
return 1
85+
fi
86+
}
87+
88+
check_prerequisites() {
89+
print_status "Checking prerequisites..."
90+
91+
# Check if kubectl is available
92+
if ! command -v kubectl >/dev/null 2>&1; then
93+
print_error "kubectl is required but not installed"
94+
return 1
95+
fi
96+
97+
# Check if we can connect to cluster
98+
if ! kubectl cluster-info >/dev/null 2>&1; then
99+
print_error "Cannot connect to Kubernetes cluster"
100+
return 1
101+
fi
102+
103+
print_success "Prerequisites check passed"
104+
}
105+
106+
cleanup() {
107+
print_status "Cleaning up deployment files..."
108+
109+
if [ -f "k8s/00-secrets-deploy.yaml" ]; then
110+
rm k8s/00-secrets-deploy.yaml
111+
print_success "Deployment secrets file removed"
112+
fi
113+
}
114+
115+
main() {
116+
echo "NetPulse Kubernetes Secrets Setup"
117+
echo "=================================="
118+
119+
case "${1:-help}" in
120+
"generate")
121+
check_prerequisites
122+
generate_secure_values
123+
print_success "Secrets generation complete!"
124+
print_status "Next step: kubectl apply -f k8s/00-secrets-deploy.yaml"
125+
;;
126+
"apply")
127+
check_prerequisites
128+
apply_secrets
129+
print_success "Secrets applied to cluster!"
130+
print_status "Next step: kubectl apply -f k8s/01-redis.yaml"
131+
;;
132+
"auto")
133+
check_prerequisites
134+
generate_secure_values
135+
apply_secrets
136+
print_success "Complete setup finished!"
137+
print_status "Next step: kubectl apply -f k8s/01-redis.yaml"
138+
print_warning "Deployment file k8s/00-secrets-deploy.yaml kept for reference"
139+
print_status "Run '$0 cleanup' to remove deployment files when done"
140+
;;
141+
"cleanup")
142+
cleanup
143+
;;
144+
"help"|*)
145+
echo "Usage: $0 {generate|apply|auto|cleanup}"
146+
echo ""
147+
echo "Commands:"
148+
echo " generate - Generate secure secrets file (k8s/00-secrets-deploy.yaml)"
149+
echo " apply - Apply secrets to Kubernetes cluster (auto-detect file)"
150+
echo " auto - Generate and apply secrets in one step (recommended)"
151+
echo " cleanup - Remove deployment files"
152+
echo ""
153+
echo "Deployment Options:"
154+
echo " Option 1 (Auto): $0 auto"
155+
echo " Option 2 (Manual): Edit k8s/00-secrets.yaml, then kubectl apply -f k8s/00-secrets.yaml"
156+
echo ""
157+
echo "File Management:"
158+
echo " k8s/00-secrets-deploy.yaml - Deployment file (auto-generated, not in git)"
159+
echo " $0 cleanup - Remove deployment files when done"
160+
echo ""
161+
echo "Examples:"
162+
echo " $0 auto # Generate and apply secrets automatically"
163+
echo " $0 generate && $0 apply # Generate first, then apply"
164+
echo " kubectl apply -f k8s/00-secrets.yaml # Use manually edited file"
165+
echo " $0 cleanup # Clean up temporary files"
166+
;;
167+
esac
168+
}
169+
170+
main "$@"

0 commit comments

Comments
 (0)