Add namespace, secret for image registry, and prod configs

This commit is contained in:
Agent
2026-03-20 10:21:33 +00:00
parent f70ba958c7
commit fe66d197aa
9 changed files with 124 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-backend
namespace: todo-test
labels:
app: todo-backend
spec:
@@ -14,10 +15,12 @@ spec:
labels:
app: todo-backend
spec:
imagePullSecrets:
- name: todo-registry-secret
containers:
- name: todo-backend
image: todo-backend:latest
imagePullPolicy: IfNotPresent
image: ccr.ccs.tencentyun.com/todo-test/todo-backend:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
env:
@@ -34,7 +37,7 @@ spec:
- name: SPRING_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: todo-secret
name: todo-db-secret
key: DATABASE_PASSWORD
- name: SPRING_REDIS_HOST
valueFrom:
@@ -70,6 +73,7 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
name: todo-postgres
namespace: todo-test
labels:
app: todo-postgres
spec:
@@ -99,7 +103,7 @@ spec:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: todo-secret
name: todo-db-secret
key: DATABASE_PASSWORD
volumeMounts:
- name: postgres-data
@@ -124,6 +128,7 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
name: todo-redis
namespace: todo-test
labels:
app: todo-redis
spec:
@@ -142,7 +147,7 @@ spec:
image: redis:7-alpine
ports:
- containerPort: 6379
command: ["redis-server", "--requirepass", ""]
command: ["redis-server"]
resources:
requests:
memory: "128Mi"

View File

@@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: todo-backend
namespace: todo-test
spec:
type: ClusterIP
selector:
@@ -15,6 +16,7 @@ apiVersion: v1
kind: Service
metadata:
name: todo-postgres
namespace: todo-test
spec:
type: ClusterIP
selector:
@@ -28,6 +30,7 @@ apiVersion: v1
kind: Service
metadata:
name: todo-redis
namespace: todo-test
spec:
type: ClusterIP
selector:

View File

@@ -2,6 +2,19 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: todo-config
namespace: todo-test
data:
DATABASE_URL: "jdbc:postgresql://todo-postgres:5432/building_materials"
DATABASE_USERNAME: "postgres"
REDIS_HOST: "todo-redis"
REDIS_PORT: "6379"
API_BASE_URL: "http://todo-backend:8080"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: todo-config
namespace: todo-prod
data:
DATABASE_URL: "jdbc:postgresql://todo-postgres:5432/building_materials"
DATABASE_USERNAME: "postgres"

View File

@@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-frontend
namespace: todo-test
labels:
app: todo-frontend
spec:
@@ -14,10 +15,12 @@ spec:
labels:
app: todo-frontend
spec:
imagePullSecrets:
- name: todo-registry-secret
containers:
- name: todo-frontend
image: todo-frontend:latest
imagePullPolicy: IfNotPresent
image: ccr.ccs.tencentyun.com/todo-test/todo-frontend:latest
imagePullPolicy: Always
ports:
- containerPort: 80
env:

View File

@@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: todo-frontend
namespace: todo-test
spec:
type: NodePort
selector:

13
k8s/namespace.yaml Normal file
View File

@@ -0,0 +1,13 @@
apiVersion: v1
kind: Namespace
metadata:
name: todo-test
labels:
env: test
---
apiVersion: v1
kind: Namespace
metadata:
name: todo-prod
labels:
env: production

50
k8s/prod/deployment.yaml Normal file
View File

@@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-frontend
namespace: todo-prod
labels:
app: todo-frontend
spec:
replicas: 2
selector:
matchLabels:
app: todo-frontend
template:
metadata:
labels:
app: todo-frontend
spec:
imagePullSecrets:
- name: todo-registry-secret
containers:
- name: todo-frontend
image: ccr.ccs.tencentyun.com/todo-prod/todo-frontend:v1.0.0
imagePullPolicy: Always
ports:
- containerPort: 80
env:
- name: API_BASE_URL
valueFrom:
configMapKeyRef:
name: todo-config
key: API_BASE_URL
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "200m"
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5

14
k8s/prod/service.yaml Normal file
View File

@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: todo-frontend
namespace: todo-prod
spec:
type: NodePort
selector:
app: todo-frontend
ports:
- port: 80
targetPort: 80
protocol: TCP
nodePort: 30080

View File

@@ -1,7 +1,18 @@
apiVersion: v1
kind: Secret
metadata:
name: todo-secret
type: Opaque
stringData:
DATABASE_PASSWORD: "postgres"
name: todo-registry-secret
namespace: todo-test
type: kubernetes.io/dockerconfigjson
data:
# base64 encoded: {"auths":{"ccr.ccs.tencentyun.com":{"username":"100024540033","password":"Mb83201048","email":"","auth":"MTAwMDI0NTQwMDMzOk1iODMyMDE0OA=="}}}
.dockerconfigjson: eyJhdXRocyI6eyJjY3IuY2NzLnRlbmNlbnR5dW4uY29tIjp7InVzZXJuYW1lIjoiMTAwMDI0NTQwMzMiLCJwYXNzd29yZCI6Ik1iODMyMDE0OCIsImVtYWlsIjoiIiwiYXV0aCI6Ik1hVjFhM2xFYldFPSJ9fX0=
---
apiVersion: v1
kind: Secret
metadata:
name: todo-registry-secret
namespace: todo-prod
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: eyJhdXRocyI6eyJjY3IuY2NzLnRlbmNlbnR5dW4uY29tIjp7InVzZXJuYW1lIjoiMTAwMDI0NTQwMzMiLCJwYXNzd29yZCI6Ik1iODMyMDE0OCIsImVtYWlsIjoiIiwiYXV0aCI6Ik1hVjFhM2xFYldFPSJ9fX0=