minio/docs/zh_CN/orchestration/kubernetes-yaml/README.md

19 KiB
Raw Blame History

使用Kubernetes做MinIO的云原生部署 Slack Docker Pulls

目录

前提条件

运行该示例你需要安装并运行Kubernetes版本>=1.4的集群,而且已经安装 kubectl 命令行工具。请访问 getting started guides获取响应平台的安装指导。

MinIO Standalone模式部署

以下部分描述了如何在Kubernetes上部署一个独立的 MinIO 服务。部署使用的是Docker Hub上的 官方MinIO Docker image

此部分使用了以下Kubernetes的核心组件:

MinIO独立模式快速入门

运行下面的命令快速启动

kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-standalone-pvc.yaml?raw=true
kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-standalone-deployment.yaml?raw=true
kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-standalone-service.yaml?raw=true

创建持久卷声明

MinIO需要持久卷来存储对象。如果没有持久卷MinIO实例中的数据将会存到容器的文件系统中而且在容器重启时会被清除的干干净净。 创建一个持久卷声明PVC为MinIO实例请求存储。Kubernetes寻找与群集中的PVC请求匹配的PV并自动将其绑定到PVC。

这是一个PVC的描述

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  # 此名称唯一标识PVC。 将在以下部署中使用。
  name: minio-pv-claim
  annotations:
    volume.alpha.kubernetes.io/storage-class: anything
  labels:
    app: minio-storage-claim
spec:
  # 关于 access modes的更多细节访问这里: http://kubernetes.io/docs/user-guide/persistent-volumes/#access-modes
  accessModes:
    - ReadWriteOnce
  resources:
    # This is the request for storage. Should be available in the cluster.
    requests:
      storage: 10Gi

创建一个持久卷声明

kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-standalone-pvc.yaml?raw=true
persistentvolumeclaim "minio-pv-claim" created

创建MinIO的部署

部署封装了副本集和pod - 因此如果pod掉线复制控制器会确保另一个pod自动出现。 这样您就不必担心pod失败并且可以提供稳定的MinIO服务。

这是一个部署的描述

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  # This name uniquely identifies the Deployment
  name: minio-deployment
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        # Label is used as selector in the service.
        app: minio
    spec:
      # Refer to the PVC created earlier
      volumes:
      - name: data
        persistentVolumeClaim:
          # Name of the PVC created earlier
          claimName: minio-pv-claim
      containers:
      - name: minio
        # Pulls the default MinIO image from Docker Hub
        image: minio/minio:RELEASE.2017-05-05T01-14-51Z
        args:
        - server
        - /data
        env:
        # MinIO access key and secret key
        - name: MINIO_ROOT_USER
          value: "minio"
        - name: MINIO_ROOT_PASSWORD
          value: "minio123"
        ports:
        - containerPort: 9000
        # Mount the volume into the pod
        volumeMounts:
        - name: data # must match the volume name, above
          mountPath: "/data"

创建一个部署

kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-standalone-deployment.yaml?raw=true
deployment "minio-deployment" created

创建Miniio服务

现在您正在运行MinIO部署您可能希望在内部集群内访问它或者将其作为服务暴露在外部集群外部也可能是公共InternetIP地址具体取决于用例。 您可以使用服务来实现此目的。 有三种主要的服务类型 - 默认类型是ClusterIP它将集群内部的连接暴露给服务。 NodePort和LoadBalancer是向外部流量提供服务的两种类型。

在此示例中我们通过创建LoadBalancer服务来公开MinIO部署。 这是服务描述。

apiVersion: v1
kind: Service
metadata:
  name: minio-service
spec:
  type: LoadBalancer
  ports:
    - port: 9000
      targetPort: 9000
      protocol: TCP
  selector:
    app: minio

创建MinIO服务

kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-standalone-service.yaml?raw=true
service "minio-service" created

LoadBalancer 服务需要几分钟才能启动。 要检查服务是否已成功创建,请运行命令

kubectl get svc minio-service
NAME            CLUSTER-IP     EXTERNAL-IP       PORT(S)          AGE
minio-service   10.55.248.23   104.199.249.165   9000:31852/TCP   1m

更新已有的MinIO部署

您可以更新现有的MinIO部署以使用较新的MinIO版本。 为此,请使用kubectl set image命令:

kubectl set image deployment/minio-deployment minio=<replace-with-new-minio-image>

Kubernetes将重新启动部署以更新镜像。 成功更新后,您将收到以下消息:

deployment "minio-deployment" image updated

独立模式资源清理

你可以清理集群占用的资源,请运行:

kubectl delete deployment minio-deployment \
&&  kubectl delete pvc minio-pv-claim \
&& kubectl delete svc minio-service

MinIO分布式服务部署

以下文档介绍了在Kubernetes上部署分布式MinIO服务器的过程。 本示例使用Docker Hub的官方MinIO Docker镜像

此示例使用以下Kubernetes的核心组件

分布式快速入门

运行下面的命令快速启动

kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-distributed-headless-service.yaml?raw=true
kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-distributed-statefulset.yaml?raw=true
kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-distributed-service.yaml?raw=true

###创建MinIO Headless服务

Headless服务控制在其中创建StatefulSets的域。此服务管理的域采用以下格式$(service name).$(namespace).svc.cluster.local其中“cluster.local”是集群域此域中的pod采用形式: $(pod-name-{i}).$(service name).$(namespace).svc.cluster.local。这里需要DNS来解析在Statefulset中创建的每个pods的URL。

这是Headless service的描述。

apiVersion: v1
kind: Service
metadata:
  name: minio
  labels:
    app: minio
spec:
  clusterIP: None
  ports:
    - port: 9000
      name: minio
  selector:
    app: minio

创建Headless服务

$ kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-distributed-headless-service.yaml?raw=true
service "minio" created

###创建MinIO Statefulset

StatefulSet为每个pod提供确定性名称和唯一身份从而轻松部署有状态的分布式应用程序。 要启动分布式MinIO您需要将驱动器位置作为参数传递到minio服务的命令。 然后您需要在所有参与的pod上运行相同的命令。 StatefulSets提供了一个完美的方式来处理这个要求。

这是Statefulset的描述。

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: minio
spec:
  serviceName: minio
  replicas: 4
  template:
    metadata:
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
      labels:
        app: minio
    spec:
      containers:
      - name: minio
        env:
        - name: MINIO_ROOT_USER
          value: "minio"
        - name: MINIO_ROOT_PASSWORD
          value: "minio123"
        image: minio/minio:RELEASE.2017-05-05T01-14-51Z
        args:
        - server
        - http://minio-0.minio.default.svc.cluster.local/data
        - http://minio-1.minio.default.svc.cluster.local/data
        - http://minio-2.minio.default.svc.cluster.local/data
        - http://minio-3.minio.default.svc.cluster.local/data
        ports:
        - containerPort: 9000
        # These volume mounts are persistent. Each pod in the PetSet
        # gets a volume mounted based on this field.
        volumeMounts:
        - name: data
          mountPath: /data
  # These are converted to volume claims by the controller
  # and mounted at the paths mentioned above.
  volumeClaimTemplates:
  - metadata:
      name: data
      annotations:
        volume.alpha.kubernetes.io/storage-class: anything
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 10Gi

创建Statefulset

$ kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-distributed-statefulset.yaml?raw=true
statefulset "minio" created

创建负载均衡服务

现在您已经运行了MinIO statefulset您可能希望在内部集群内访问它或将其作为服务暴露在外部集群外也可能是公用Internet的IP地址具体取决于用例。 您可以使用服务来实现此目的。 有三种主要的服务类型 - 默认类型是ClusterIP它将集群内部的连接暴露给服务。 NodePort和LoadBalancer是向外部流量提供服务的两种类型。

在此示例中我们通过创建LoadBalancer服务来公开MinIO部署。 这是服务描述。

apiVersion: v1
kind: Service
metadata:
  name: minio-service
spec:
  type: LoadBalancer
  ports:
    - port: 9000
      targetPort: 9000
      protocol: TCP
  selector:
    app: minio

创建MinIO service

$ kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-distributed-service.yaml?raw=true
service "minio-service" created

LoadBalancer 服务需要几分钟才能启动。 要检查服务是否已成功创建,请运行命令

$ kubectl get svc minio-service
NAME            CLUSTER-IP     EXTERNAL-IP       PORT(S)          AGE
minio-service   10.55.248.23   104.199.249.165   9000:31852/TCP   1m

###更新已经存在的MinIO StatefulSet 您可以更新现有的MinIO StatefulSet以使用较新的MinIO版本。 为此,请使用kubectl patch statefulset命令:

kubectl patch statefulset minio --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"<replace-with-new-minio-image>"}]'

成功更新后,您应该会看到下面的输出

statefulset "minio" patched

然后如下所示逐一删除StatefulSet中的所有pod。 Kubernetes将使用新的镜像为您重新启动那些pod。

kubectl delete minio-0

分布式模式资源清理

你可以使用以下命令清理集群

kubectl delete statefulset minio \
&&  kubectl delete svc minio \
&& kubectl delete svc minio-service

MinIO GCS网关部署

以下部分介绍在Kubernetes上部署MinIOGCS Gateway的过程。 部署使用Docker Hub的官方MinIO Docker映像

此示例使用以下Kubernetes的核心组件

GCS 网关快速入门

按照 这里描述的步骤创建Google云服务认证凭据文件。

使用上面生成的文件来创建一个Kubernetessecret

kubectl create secret generic gcs-credentials --from-file=/path/to/gcloud/credentials/application_default_credentials.json

下载 minio-gcs-gateway-deployment.yaml

wget https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-gcs-gateway-deployment.yaml?raw=true

使用你的GCS project ID更新 gcp_project_id部分的内容,然后运行

kubectl create -f minio-gcs-gateway-deployment.yaml
kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-gcs-gateway-service.yaml?raw=true

创建GCS凭据

凭据旨在保存敏感信息例如密码OAuth令牌和ssh密钥。 将这些信息放在一个凭据中比将其逐字地放在pod定义或docker镜像中更安全更灵活。

按照 这里描述的步骤创建Google云服务认证凭据文件。

使用上面生成的文件来创建一个Kubernetessecret

kubectl create secret generic gcs-credentials --from-file=/path/to/gcloud/credentials/application_default_credentials.json

创建MinIO GCS Gateway部署

部署封装了副本集和pod - 因此如果pod掉线复制控制器会确保另一个pod自动出现。 这样您就不必担心pod失败并且可以提供稳定的MinIO服务。

MinIO Gateway使用GCS作为其存储后端需要使用GCP“projectid”来识别您的凭据。 使用GCS项目ID更新“gcp_project_id”部分。 这是部署描述。

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  # This name uniquely identifies the Deployment
  name: minio-deployment
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        # Label is used as selector in the service.
        app: minio
    spec:
      # Refer to the secret created earlier
      volumes:
      - name: gcs-credentials
        secret:
          # Name of the Secret created earlier
          secretName: gcs-credentials
      containers:
      - name: minio
        # Pulls the default MinIO image from Docker Hub
        image: minio/minio:RELEASE.2017-08-05T00-00-53Z
        args:
        - gateway
        - gcs
        - gcp_project_id
        env:
        # MinIO access key and secret key
        - name: MINIO_ROOT_USER
          value: "minio"
        - name: MINIO_ROOT_PASSWORD
          value: "minio123"
        # Google Cloud Service uses this variable
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: "/etc/credentials/application_default_credentials.json"
        ports:
        - containerPort: 9000
        # Mount the volume into the pod
        volumeMounts:
        - name: gcs-credentials
          mountPath: "/etc/credentials"
          readOnly: true

创建部署

kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-gcs-gateway-deployment.yaml?raw=true
deployment "minio-deployment" created

创建MinIO LoadBalancer服务

现在您正在运行MinIO您可能希望在内部集群内访问它或者将其作为服务暴露在外部集群外部也可能是公共InternetIP地址具体取决于用例。 您可以使用服务来实现此目的。 有三种主要的服务类型 - 默认类型是ClusterIP它将集群内部的连接暴露给服务。 NodePort和LoadBalancer是向外部流量提供服务的两种类型。

在此示例中我们通过创建LoadBalancer服务来暴露MinIO。 这是服务描述。

apiVersion: v1
kind: Service
metadata:
  name: minio-service
spec:
  type: LoadBalancer
  ports:
    - port: 9000
      targetPort: 9000
      protocol: TCP
  selector:
    app: minio

创建MinIO服务

kubectl create -f https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-gcs-gateway-service.yaml?raw=true
service "minio-service" created

LoadBalancer服务需要几分钟才能启动。 要检查服务是否已成功创建,请运行命令

kubectl get svc minio-service
NAME            CLUSTER-IP     EXTERNAL-IP       PORT(S)          AGE
minio-service   10.55.248.23   104.199.249.165   9000:31852/TCP   1m

更新现有的MinIO GCS部署

您可以更新现有的MinIO部署以使用较新的MinIO版本。 为此,请使用kubectl set image命令:

kubectl set image deployment/minio-deployment minio=<replace-with-new-minio-image>

Kubernetes将重新启动部署以更新镜像。 成功更新后,您将收到以下消息:

deployment "minio-deployment" image updated

GCS网关资源清理

你可以使用下面的命令清理集群

kubectl delete deployment minio-deployment \
&&  kubectl delete secret gcs-credentials