前提条件

  • 集群安装StorageClass作为数据存储

安装MinIO StatefulSet

cat > minio.yaml << EOF
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: minio
spec:
  serviceName: "minio-headless"
  replicas: 4
  selector:
    matchLabels:
      app: minio
  template:
    metadata:
      labels:
        app: minio
    spec:
      # nodeSelector:
      #   minio: true
      containers:
      - name: minio
        env:
        - name: MINIO_ROOT_USER
          value: "admin"
        - name: MINIO_ROOT_PASSWORD
          value: "123456"
        image: minio/minio:RELEASE.2024-07-04T14-25-45Z
        imagePullPolicy: IfNotPresent
        command:
          - /bin/sh
          - -c
          - minio server --console-address ":5000" http://minio-{0...3}.minio-headless:9000/data
        ports:
        - name: data
          containerPort: 9000
          protocol: "TCP"
        - name: console
          containerPort: 5000
          protocol: "TCP"
        volumeMounts:
        - name: data
          mountPath: /data
        - name: time-mount
          mountPath: /etc/localtime
      volumes:
      - name: time-mount
        hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      storageClassName: "rook-ceph-block"
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 200Gi
EOF
kubectl apply -f minio.yaml
# 可选,如果取消掉nodeSelector注释时,需要在node打标签
kubectl label node k8s-worker01 minio=true
kubectl label node k8s-worker02 minio=true
kubectl label node k8s-worker03 minio=true

配置Headless和NodePort

cat > minio-svc.yaml << EOF
apiVersion: v1
kind: Service
metadata:
  name: minio-headless
  labels:
    app: minio
spec:
  clusterIP: None
  ports:
    - port: 9000
      name: data
  selector:
    app: minio
---
apiVersion: v1
kind: Service
metadata:
  name: minio-service
spec:
  type: NodePort
  ports:
   - name: data
     nodePort: 30009
     port: 9000
     targetPort: 9000
   - name: console
     nodePort: 31901
     port: 5000
     targetPort: 30005
  selector:
    app: minio
EOF
kubectl apply -f minio-svc.yaml

访问WebUI