Skip to content

Instantly share code, notes, and snippets.

@benjaminknox
Created December 8, 2023 19:00
Show Gist options
  • Save benjaminknox/184aaba636c4510a4e3258f2aefe1537 to your computer and use it in GitHub Desktop.
Save benjaminknox/184aaba636c4510a4e3258f2aefe1537 to your computer and use it in GitHub Desktop.
Deploying Minio to k8s as a StatefulSet

Deploying Minio to k8s as a StatefulSet

Minio is an S3 compatible object storage application that is free to use and built to deploy into a kubernetes cluster. This guide is a set of instructions for deploying Minio into your cluster, it will walk through creating a persistent volume, statefulset, and service on a loadbalancer.

Before anything else we may want to create a new namespace in our cluster for minio, should you want to separate out this deployment you can with this command:

$  kubectl create namespace minio

The first step is to create a place to store the applications state, mostly the files that are uploaded as objects through the API. There are a few options for volumes, see volumes docs for more info, for this guide we will create a simple persistent volume, however, you will need to determine the best volume to run in your cluster.

The command below sets up a persistent volume, adjust the storage size value to meet your needs, currently it is set to 10 gigabytes (see the spec.resources.requests.storage value):

$ kubectl apply -f - <<EOF
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: minio
  name: minio-pv-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
EOF

Now that we have storage we can create the minio statefulset, you will want to change the user environment variables to match your environment before deploying:

$ kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: StatefulSet
metadata:
  namespace: minio
  name: minio
spec:
  selector:
    matchLabels:
      app: minio
  template:
    metadata:
      labels:
        app: minio
    spec:
      containers:
        - name: minio
          env:
            - name: MINIO_ROOT_USER
              value: "admin"
            - name: MINIO_ROOT_PASSWORD
              value: "passwd_for_admin"
          image: quay.io/minio/minio
          imagePullPolicy: IfNotPresent
          args:
            - server
            - /data
            - "--console-address=:9001"
          ports:
            - name: api
              containerPort: 9000
              hostPort: 9000
              protocol: TCP
            - name: console
              containerPort: 9001
              hostPort: 9001
              protocol: TCP
          resources:
            limits:
              cpu: 2000m
              memory: 2Gi
            requests:
              cpu: 1000m
              memory: 1Gi
          volumeMounts:
            - name: data
              mountPath: /data
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: minio-pv-claim
EOF

This creates a minio statefulset, note that there is not work done for scaling, here's an example of how you could create a minio statefulset with 4 replicasets.

Next step in the process is creating a service, for this we're going to deploy using a LoadBalancer:

$ kubectl apply -f - <<EOF
apiVersion: v1
kind: Service
metadata:
  namespace: minio
  name: minio-service
spec:
  selector:
    app: minio
  type: LoadBalancer
  ports:
  - name: api
    protocol: TCP
    port: 9000
    targetPort: 9000
  - name: console
    protocol: TCP
    port: 9001
    targetPort: 9001
EOF

The service configuration will need to be specific to your cluser, but if you are you set up with minikube locally you should be able to see minio at http://localhost:9001.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment