268 lines
5.7 KiB
YAML
268 lines
5.7 KiB
YAML
# MinIO 文件服务器部署配置
|
||
# 用于 Gitea Runner 测试报告存储
|
||
|
||
---
|
||
# 1. Secret - MinIO 访问凭据
|
||
apiVersion: v1
|
||
kind: Secret
|
||
metadata:
|
||
name: minio-credentials
|
||
namespace: storage
|
||
type: Opaque
|
||
stringData:
|
||
# Root 用户凭据(可自定义)
|
||
root-user: "minioadmin"
|
||
root-password: "minioadmin123"
|
||
|
||
---
|
||
# 2. PVC - 持久化存储
|
||
apiVersion: v1
|
||
kind: PersistentVolumeClaim
|
||
metadata:
|
||
name: minio-storage
|
||
namespace: storage
|
||
spec:
|
||
accessModes:
|
||
- ReadWriteOnce
|
||
resources:
|
||
requests:
|
||
storage: 20Gi # 测试报告存储空间
|
||
# storageClassName: "" # 使用默认 StorageClass
|
||
|
||
---
|
||
# 3. Deployment - MinIO 服务
|
||
apiVersion: apps/v1
|
||
kind: Deployment
|
||
metadata:
|
||
name: minio
|
||
namespace: storage
|
||
labels:
|
||
app: minio
|
||
spec:
|
||
replicas: 1 # 单实例部署(适合测试环境)
|
||
selector:
|
||
matchLabels:
|
||
app: minio
|
||
template:
|
||
metadata:
|
||
labels:
|
||
app: minio
|
||
spec:
|
||
containers:
|
||
- name: minio
|
||
image: minio/minio:latest
|
||
args:
|
||
- server
|
||
- /data
|
||
- --console-address
|
||
- ":9001" # Console 端口
|
||
env:
|
||
# Root 用户凭据
|
||
- name: MINIO_ROOT_USER
|
||
valueFrom:
|
||
secretKeyRef:
|
||
name: minio-credentials
|
||
key: root-user
|
||
- name: MINIO_ROOT_PASSWORD
|
||
valueFrom:
|
||
secretKeyRef:
|
||
name: minio-credentials
|
||
key: root-password
|
||
|
||
# 区域设置
|
||
- name: MINIO_REGION_NAME
|
||
value: "us-east-1"
|
||
|
||
# 浏览器访问配置
|
||
- name: MINIO_BROWSER
|
||
value: "on"
|
||
|
||
# Prometheus metrics
|
||
- name: MINIO_PROMETHEUS_AUTH_TYPE
|
||
value: "public"
|
||
|
||
ports:
|
||
- name: api
|
||
containerPort: 9000
|
||
protocol: TCP
|
||
- name: console
|
||
containerPort: 9001
|
||
protocol: TCP
|
||
|
||
volumeMounts:
|
||
- name: data
|
||
mountPath: /data
|
||
|
||
# 健康检查
|
||
livenessProbe:
|
||
httpGet:
|
||
path: /minio/health/live
|
||
port: 9000
|
||
initialDelaySeconds: 30
|
||
periodSeconds: 10
|
||
timeoutSeconds: 5
|
||
failureThreshold: 3
|
||
|
||
readinessProbe:
|
||
httpGet:
|
||
path: /minio/health/ready
|
||
port: 9000
|
||
initialDelaySeconds: 10
|
||
periodSeconds: 10
|
||
timeoutSeconds: 5
|
||
failureThreshold: 3
|
||
|
||
# 资源限制
|
||
resources:
|
||
requests:
|
||
cpu: 100m
|
||
memory: 256Mi
|
||
limits:
|
||
cpu: 1000m
|
||
memory: 1Gi
|
||
|
||
volumes:
|
||
- name: data
|
||
persistentVolumeClaim:
|
||
claimName: minio-storage
|
||
|
||
---
|
||
# 4. Service - MinIO API(S3 兼容接口)
|
||
apiVersion: v1
|
||
kind: Service
|
||
metadata:
|
||
name: minio
|
||
namespace: storage
|
||
labels:
|
||
app: minio
|
||
spec:
|
||
type: ClusterIP
|
||
ports:
|
||
- name: api
|
||
port: 9000
|
||
targetPort: 9000
|
||
protocol: TCP
|
||
selector:
|
||
app: minio
|
||
|
||
---
|
||
# 5. Service - MinIO API(NodePort 外部访问)
|
||
apiVersion: v1
|
||
kind: Service
|
||
metadata:
|
||
name: minio-api-external
|
||
namespace: storage
|
||
labels:
|
||
app: minio
|
||
spec:
|
||
type: NodePort
|
||
ports:
|
||
- name: api
|
||
port: 9000
|
||
targetPort: 9000
|
||
nodePort: 31000 # MinIO API 外部端口
|
||
protocol: TCP
|
||
selector:
|
||
app: minio
|
||
|
||
---
|
||
# 6. Service - MinIO Console(管理界面)
|
||
apiVersion: v1
|
||
kind: Service
|
||
metadata:
|
||
name: minio-console
|
||
namespace: storage
|
||
labels:
|
||
app: minio
|
||
spec:
|
||
type: NodePort
|
||
ports:
|
||
- name: console
|
||
port: 9001
|
||
targetPort: 9001
|
||
nodePort: 31001 # MinIO Console 外部端口
|
||
protocol: TCP
|
||
selector:
|
||
app: minio
|
||
|
||
---
|
||
# 7. ConfigMap - MinIO Client (mc) 配置
|
||
apiVersion: v1
|
||
kind: ConfigMap
|
||
metadata:
|
||
name: minio-init-scripts
|
||
namespace: storage
|
||
data:
|
||
init-buckets.sh: |
|
||
#!/bin/sh
|
||
set -e
|
||
|
||
echo "Waiting for MinIO to be ready..."
|
||
until mc alias set myminio http://minio:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD}; do
|
||
echo "MinIO not ready yet, retrying in 5 seconds..."
|
||
sleep 5
|
||
done
|
||
|
||
echo "MinIO is ready!"
|
||
|
||
# 创建测试报告存储桶
|
||
echo "Creating bucket: test-reports"
|
||
mc mb --ignore-existing myminio/test-reports
|
||
|
||
# 设置公共读访问策略(便于查看报告)
|
||
echo "Setting public read policy for test-reports"
|
||
mc anonymous set download myminio/test-reports
|
||
|
||
# 创建其他可能需要的桶
|
||
echo "Creating bucket: artifacts"
|
||
mc mb --ignore-existing myminio/artifacts
|
||
mc anonymous set download myminio/artifacts
|
||
|
||
echo "Creating bucket: cache (for CI/CD cache)"
|
||
mc mb --ignore-existing myminio/cache
|
||
|
||
echo "✅ MinIO initialization completed!"
|
||
|
||
# 显示桶列表
|
||
echo "Current buckets:"
|
||
mc ls myminio
|
||
|
||
---
|
||
# 8. Job - 初始化 MinIO(创建 buckets)
|
||
apiVersion: batch/v1
|
||
kind: Job
|
||
metadata:
|
||
name: minio-init
|
||
namespace: storage
|
||
spec:
|
||
ttlSecondsAfterFinished: 300 # Job 完成后 5 分钟自动清理
|
||
template:
|
||
metadata:
|
||
labels:
|
||
app: minio-init
|
||
spec:
|
||
restartPolicy: OnFailure
|
||
containers:
|
||
- name: mc
|
||
image: minio/mc:latest
|
||
command: ["/bin/sh", "/scripts/init-buckets.sh"]
|
||
env:
|
||
- name: MINIO_ROOT_USER
|
||
valueFrom:
|
||
secretKeyRef:
|
||
name: minio-credentials
|
||
key: root-user
|
||
- name: MINIO_ROOT_PASSWORD
|
||
valueFrom:
|
||
secretKeyRef:
|
||
name: minio-credentials
|
||
key: root-password
|
||
volumeMounts:
|
||
- name: scripts
|
||
mountPath: /scripts
|
||
volumes:
|
||
- name: scripts
|
||
configMap:
|
||
name: minio-init-scripts
|
||
defaultMode: 0755
|