在k8s中以deployment方式部署minio

minio官网给的demo是通过pod方式部署的,我碰到了好几次因为k8s集群断电重启后,以单pod方式部署部署的minio消失。因此这里改用deplyment的方式部署minio。

以下是完整的minio部署清单

---
# 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:
  name: minio
  namespace: devops
spec:
  replicas: 1
  selector:
    matchLabels:
      app: minio
  template:
    metadata:
      labels:
        app: minio
    spec:
      containers:
      - name: minio
        image: 192.168.10.30:9000/minio:latest
        command:
        - /bin/bash
        - -c
        args:
        - minio server /data --console-address :9001
        env:
          - name: MINIO_SERVER_URL
            value: 'http://minio.rockstics.com'
          - name: MINIO_BROWSER_REDIRECT_URL
            value: 'http://minio.rockstics.com/minio/ui'
        volumeMounts:
        - mountPath: /data
          name: localvolume # Corresponds to the `spec.volumes` Persistent Volume
      hostAliases:
        - ip: "192.168.10.188"
          hostnames:
          - "minio.rockstics.com"
      volumes:
      - name: localvolume
        hostPath: # MinIO generally recommends using locally-attached volumes
          path: /data/minio # Specify a path to a local drive or volume on the Kubernetes worker node
          type: DirectoryOrCreate # The path to the last directory must exist
      nodeSelector:
        kubernetes.io/hostname: kubernetesw02

---
kind: Service
apiVersion: v1
metadata:
  name: minio-server
  namespace: devops
  labels:
    app: minio-server
spec:
  ports:
    - name: http-console
      protocol: TCP
      port: 9001
      targetPort: 9001
    - name: http-api
      protocol: TCP
      port: 9000
      targetPort: 9000
  selector:
    app: minio
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  annotations:
  labels:
    app: minio
  name: minio
  namespace: devops
spec:
  routes:
    - kind: Rule
      match: Host(`minio.isiact.com`)
      services:
        - kind: Service
          name: minio-server
          namespace: devops
          port: http-api
    - kind: Rule
      match: Host(`minio.isiact.com`) && PathPrefix(`/minio/ui`)
      middlewares:
        - name: minio-console
      services:
        - kind: Service
          name: minio-server
          namespace: devops
          port: http-console
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  annotations:
  name: minio-console
  namespace: devops
spec:
  stripPrefix:
    prefixes:
      - /minio/ui

题外话:由于我通过MINIO_SERVER_URL指定了minio的内网访问域名,导致登录minio报"invalid login"的问题,刚开始以为是挂载的数据路径中有.minio.sys 相关信息(包括minio配置信息包括用户密码,assce_key等信息)被其他容器挂载无效,实践证明不是这样的,后来才发现是因为容易内无法解析我的内网域名导致的,解决方案就是直接进行host绑定。

Kubernetes (k8s) 是一个开源容器管理系统,用于自动化容器化应用程序的部署、扩展和管理。MinIO 是一个开源的对象存储服务器,它提供了一个类似于 Amazon S3 的 API。在 Kubernetes部署 MinIO 分布式,意味着你可以将 MinIO 存储服务拆分成多个副本,以便提高可用性和容错能力。 在 k8s部署 MinIO,通常会创建一个 Deployment 和 Service 对象,步骤如下: 1. **配置yaml文件**:编写包含 MinIO 配置、镜像版本和所需资源的 `Deployment` 和 `Service` yaml 文件,比如副本数、卷挂载等。 ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: minio-deployment spec: replicas: 3 # 设置副本数 selector: matchLabels: app: minio template: metadata: labels: app: minio spec: containers: - name: minio image: minio/minio:latest ports: - containerPort: 9000 # HTTP端口 - containerPort: 9001 # HTTPS端口 env: - name: MINIO_ACCESS_KEY valueFrom: secretKeyRef: name: minio-secret key: accesskey - name: MINIO_SECRET_KEY valueFrom: secretKeyRef: name: minio-secret key: secretkey --- apiVersion: v1 kind: Service metadata: name: minio-service spec: selector: app: minio ports: - protocol: TCP port: 9000 targetPort: 9000 type: LoadBalancer ``` 2. **应用到集群**:使用 `kubectl apply -f deployment.yaml service.yaml` 将yaml文件应用到集群中。 3. **负载均衡**:由于设置了 `type: LoadBalancer`,外部网络可以通过 Kubernetes 创建的负载均衡器访问 MinIO
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值