Alice.tech

Minio的使用

前言 一时兴起了,想为nix搭一个缓存服务器 部署 minio的容器镜像官方不维护,并且开源版功能 大砍 ,所以使用社区维护的 参考https://vonng.com/db/minio resurrect/ docker…

前言

一时兴起了,想为nix搭一个缓存服务器

部署

minio的容器镜像官方不维护,并且开源版功能大砍,所以使用社区维护的

参考https://vonng.com/db/minio-resurrect/

docker-compose

version: '3.7'

# Settings and configurations that are common for all containers
x-minio-common: &minio-common
  image: pgsty/minio:latest
  command: server --console-address ":9001" http://minio{1...4}/data{1...2}
  expose:
    - "9000"
    - "9001"
  # environment:
    # MINIO_ROOT_USER: minioadmin
    # MINIO_ROOT_PASSWORD: minioadmin
  healthcheck:
    test: ["CMD", "mc", "ready", "local"]
    interval: 5s
    timeout: 5s
    retries: 5

# starts 4 docker containers running minio server instances.
# using nginx reverse proxy, load balancing, you can access
# it through port 9000.
services:
  minio1:
    <<: *minio-common
    hostname: minio1
    volumes:
      - data1-1:/data1
      - data1-2:/data2

  minio2:
    <<: *minio-common
    hostname: minio2
    volumes:
      - data2-1:/data1
      - data2-2:/data2

  minio3:
    <<: *minio-common
    hostname: minio3
    volumes:
      - data3-1:/data1
      - data3-2:/data2

  minio4:
    <<: *minio-common
    hostname: minio4
    volumes:
      - data4-1:/data1
      - data4-2:/data2

  nginx:
    image: nginx:1.19.2-alpine
    hostname: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "9000:9000"
      - "9001:9001"
    depends_on:
      - minio1
      - minio2
      - minio3
      - minio4

## By default this config uses default local driver,
## For custom volumes replace with volume driver configuration.
volumes:
  data1-1:
  data1-2:
  data2-1:
  data2-2:
  data3-1:
  data3-2:
  data4-1:
  data4-2:
docker-compose up -d

kubernetes

初步配置Pod

curl https://raw.githubusercontent.com/minio/docs/master/source/extra/examples/minio-dev.yaml -O
# Deploys a new Namespace for the MinIO Pod
apiVersion: v1
kind: Namespace
metadata:
  name: minio-dev # Change this value if you want a different namespace name
  labels:
    name: minio-dev # Change this value to match metadata.name
---
# Deploys a new MinIO Pod into the metadata.namespace Kubernetes namespace
#
# The `spec.containers[0].args` contains the command run on the pod
# The `/data` directory corresponds to the `spec.containers[0].volumeMounts[0].mountPath`
# That mount path corresponds to a Kubernetes HostPath which binds `/data` to a local drive or volume on the worker node where the pod runs
# 
apiVersion: v1
kind: Pod
metadata:
  labels:
    app: minio
  name: minio
  namespace: minio-dev # Change this value to match the namespace metadata.name
spec:
  containers:
  - name: minio
    image: pgsty/minio:latest
    command:
    - /bin/bash
    - -c
    args: 
    - minio server /data --console-address :9090
    volumeMounts:
    - mountPath: /data
      name: localvolume # Corresponds to the `spec.volumes` Persistent Volume
  nodeSelector:
    kubernetes.io/hostname: kubealpha.local # Specify a node label associated to the Worker Node on which you want to deploy the pod.
  volumes:
  - name: localvolume
    hostPath: # MinIO generally recommends using locally-attached volumes
      path: /mnt/disk1/data # Specify a path to a local drive or volume on the Kubernetes worker node
      type: DirectoryOrCreate # The path to the last directory must exist

查看节点

kubectl get nodes

更改这一行,为我们的节点

kubernetes.io/hostname: kubealpha.local # Specify a node label associated to the Worker Node on which you want to deploy the pod.

创建volume数据卷的目录

# 安装这一行
path: /mnt/disk1/data # Specify a path to a local drive or volume on the Kubernetes worker node

使用部署文件

kubectl apply -f minio-dev.ymal

查看文件里使用的命名空间

kubectl get pods -n minio-dev
root@Caat ~/W/minio_k8s# kubectl get pods -n minio-dev 
NAME    READY   STATUS    RESTARTS   AGE
minio   0/1     Pending   0          65s

有关命名空间

发现没有running,查看问题

发现是namespace 设置为了 minio 和 minio-dev 冲突了

kubectl describe pods -n minio-dev

添加deployment管理与service暴露

把pod改为deployment配置

# Deploys a new Namespace for the MinIO Pod
apiVersion: v1
kind: Namespace
metadata:
  name: minio-dev # Change this value if you want a different namespace name
  labels:
    name: minio-dev # Change this value to match metadata.name
---
# Deploys a new MinIO Pod into the metadata.namespace Kubernetes namespace
#
# The `spec.containers[0].args` contains the command run on the pod
# The `/data` directory corresponds to the `spec.containers[0].volumeMounts[0].mountPath`
# That mount path corresponds to a Kubernetes HostPath which binds `/data` to a local drive or volume on the worker node where the pod runs
# 
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: minio
  name: minio
  namespace: minio-dev # Change this value to match the namespace metadata.name
# deployment spec
spec:
  replicas: 1                    # ← 新增:要几个副本
  selector:                      # ← 新增:如何找到 Pod
    matchLabels:
      app: minio
  template:                      # ← 原来 Pod 的 spec 全部移到这下面
    metadata:
      labels:
        app: minio
    spec:
      containers:
      - name: minio
        image: pgsty/minio:latest
        command:
        - /bin/bash
        - -c
        args:
        - minio server /data --console-address :9090
        ports:
        - containerPort: 9000
          name: api
        - containerPort: 9090
          name: console
        volumeMounts:
        - mountPath: /data
          name: localvolume
      volumes:
      - name: localvolume
        hostPath:
          path: /mnt/disk1/data
          type: DirectoryOrCreate
      nodeSelector:
        kubernetes.io/hostname: caat
---
# Service 用于暴露 Deployment 中的 Pod
apiVersion: v1
kind: Service
metadata:
  name: minio-api 
  namespace: minio-dev # Change this value to match the namespace metadata.name
spec:
  selector:
    app: minio
  ports:
  - port: 9000
    targetPort: 9000
  type: NodePort
---
apiVersion: v1
kind: Service
metadata:
  name: minio-console
  namespace: minio-dev # Change this value to match the namespace metadata.name
spec:
  selector:
    app: minio
  ports:
  - port: 9090
    targetPort: 9090
  type: NodePort

姑且是这样

类型 name 作用
[deployment] minio 管理minio的Pod
[workspace] minio-dev 创建命名空间,如不额外声明默认default
[service] minio-api 提供使用Minio的端口9000
[service] minio-console 提供使用Minio Web管理的端口``

原始笔记:linux/minio的使用.md