This commit is contained in:
DullJZ
2025-09-13 22:30:40 +08:00
parent 4268f6238d
commit f214b003fd
34 changed files with 2217 additions and 10 deletions
+56
View File
@@ -0,0 +1,56 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: s3-balance-config
namespace: s3-balance
labels:
app: s3-balance
data:
config.yaml: |
# Kubernetes 生产环境配置
server:
host: "0.0.0.0"
port: 8080
read_timeout: 30s
write_timeout: 30s
idle_timeout: 60s
database:
type: "sqlite"
dsn: "/app/data/s3-balance.db"
max_open_conns: 50
max_idle_conns: 10
conn_max_lifetime: 600
log_level: "info"
auto_migrate: true
buckets:
# 示例配置 - 请替换为实际存储桶
- name: "prod-bucket-1"
endpoint: "http://minio-svc:9000"
region: "us-east-1"
access_key_id: "minioadmin"
secret_access_key: "minioadmin"
max_size: "100GB"
weight: 10
enabled: true
use_ssl: false
path_style: true
virtual: false
balancer:
strategy: "least-space"
health_check_period: 30s
update_stats_period: 60s
metrics:
enabled: true
path: "/metrics"
port: 8080
s3api:
access_key: "AKIAIOSFODNN7EXAMPLE"
secret_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
virtual_host: false
proxy_mode: false
auth_required: false
+92
View File
@@ -0,0 +1,92 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: s3-balance-deployment
namespace: s3-balance
labels:
app: s3-balance
tier: backend
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
selector:
matchLabels:
app: s3-balance
template:
metadata:
labels:
app: s3-balance
tier: backend
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- s3-balance
topologyKey: kubernetes.io/hostname
containers:
- name: s3-balance
image: s3-balance:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
name: http
env:
- name: TZ
value: "Asia/Shanghai"
volumeMounts:
- name: config
mountPath: /app/config
readOnly: true
- name: data
mountPath: /app/data
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 3
securityContext:
runAsNonRoot: true
runAsUser: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
seccompProfile:
type: RuntimeDefault
volumes:
- name: config
configMap:
name: s3-balance-config
- name: data
emptyDir: {}
restartPolicy: Always
terminationGracePeriodSeconds: 30
+40
View File
@@ -0,0 +1,40 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: s3-balance-hpa
namespace: s3-balance
labels:
app: s3-balance
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: s3-balance-deployment
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
behavior:
scaleUp:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 50
periodSeconds: 60
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 10
periodSeconds: 60
+22
View File
@@ -0,0 +1,22 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: s3-balance-ingress
namespace: s3-balance
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
spec:
ingressClassName: nginx
rules:
- host: s3-balance.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: s3-balance-service
port:
number: 8080
+7
View File
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Namespace
metadata:
name: s3-balance
labels:
app: s3-balance
tier: backend
+34
View File
@@ -0,0 +1,34 @@
apiVersion: v1
kind: Service
metadata:
name: s3-balance-service
namespace: s3-balance
labels:
app: s3-balance
spec:
selector:
app: s3-balance
ports:
- port: 8080
targetPort: 8080
protocol: TCP
name: http
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: s3-balance-metrics-service
namespace: s3-balance
labels:
app: s3-balance
service-type: metrics
spec:
selector:
app: s3-balance
ports:
- port: 8080
targetPort: 8080
protocol: TCP
name: metrics
type: ClusterIP