【问题标题】:Kubernetes Volume Mount with Replication Controllers带有复制控制器的 Kubernetes 卷挂载
【发布时间】:2016-06-08 06:23:09
【问题描述】:

为 Kubernetes EmptyDir 卷找到了这个示例

apiVersion: v1
kind: Pod
metadata:
  name: www
spec:
  containers:
  - name: nginx
    image: nginx
    volumeMounts:
    - mountPath: /srv/www
      name: www-data
      readOnly: true
  - name: git-monitor
    image: kubernetes/git-monitor
    env:
    - name: GIT_REPO
      value: http://github.com/some/repo.git
    volumeMounts:
    - mountPath: /data
      name: www-data
  volumes:
  - name: www-data
    emptyDir: {}

我想在 2 个 pod 之间进行卷挂载。我正在使用 2 个不同的复制控制器创建这些 pod。复制控制器看起来像这样

复制控制器 1:

apiVersion: v1
kind: ReplicationController
metadata:
  name: node-worker
  labels:
    name: node-worker
spec:
  replicas: 1
  selector:
    name: node-worker
  template:
    metadata:
      labels:
        name: node-worker
    spec:
      containers:
      -
        name: node-worker
        image: image/node-worker
        volumeMounts:
          - mountPath: /mnt/test
            name: deployment-volume
      volumes:
        - name: deployment-volume
          emptyDir: {}

复制控制器 2:

apiVersion: v1
    kind: ReplicationController
    metadata:
      name: node-manager
      labels:
        name: node-manager
    spec:
      replicas: 1
      selector:
        name: node-manager
      template:
        metadata:
          labels:
            name: node-manager
        spec:
          containers:
          -
            name: node-manager
            image: image/node-manager
            volumeMounts:
              - mountPath: /mnt/test
                name: deployment-volume
          volumes:
            - name: deployment-volume
              emptyDir: {}

Kubernetes emptyDir 卷可以用于这种场景吗?

【问题讨论】:

    标签: docker kubernetes mount


    【解决方案1】:

    EmptyDir 卷本质上绑定到单个 pod 的生命周期,并且不能在复制控制器或其他方式中的 pod 之间共享。如果你想在 Pod 之间共享卷,现在最好的选择是 NFS 或 gluster,在一个持久卷中。在此处查看示例:https://github.com/kubernetes/examples/blob/master/staging/volumes/nfs/README.md

    【讨论】:

    • 我正在尝试 NFS 示例。我已经设置了 NFS 服务器、pv 和 pvc,当尝试将卷挂载到 NFS 时,我在日志中看到了这个错误。 .输出:mount.nfs:不支持请求的 NFS 版本或传输协议
    • VizZy,听起来像是 nfs 客户端和服务器之间可能不匹配。服务器是什么版本?
    【解决方案2】:

    为什么要在 pod 之间共享卷挂载?这不会可靠地工作,因为不能保证在集群中调度复制控制器 1 和复制控制器 2 中的 pod 之间存在 1:1 映射。

    如果你想在容器之间共享本地存储,你应该把两个容器放在同一个 pod 中,并让每个容器挂载 emptyDir 卷。

    【讨论】:

      【解决方案3】:

      您需要 三个 的东西才能使其正常工作。更多信息可以在here 和一些文档here 中找到,但一开始有点混乱。

      此示例安装 NFS 卷。

      1.创建一个指向 NFS 服务器的 PersistentVolume

      文件:mynfssharename-pv.yaml

      (更新服务器以指向您的服务器)

      apiVersion: v1
      kind: PersistentVolume
      metadata:
        name: mynfssharename
      spec:
        capacity:
          storage: 1Gi
        accessModes:
          - ReadWriteMany
        nfs:
          server: yourservernotmine.yourcompany.com
          path: "/yournfspath"
      

      kubectl create -f mynfssharename-pv.yaml

      2。创建一个 PersistentVolumeClaim 以指向 PersistentVolume mynfssharename

      文件:mynfssharename-pvc.yaml

      apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: mynfssharename
      spec:
        accessModes:
          - ReadWriteMany
        resources:
          requests:
            storage: 1Gi
      

      kubectl create -f mynfssharename-pvc.yaml

      3.将声明添加到您的 ReplicationController 或 Deployment

      spec:
        containers:
        - name: sample-pipeline
          image: yourimage
          imagePullPolicy: Always
          ports:
          - containerPort: 8080
            name: http
          volumeMounts:
            # name must match the volume name below
            - name: mynfssharename
              mountPath: "/mnt"
        volumes:
        - name: mynfssharename
          persistentVolumeClaim:
            claimName: mynfssharename
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-11
        • 2020-08-07
        • 1970-01-01
        • 2019-08-24
        • 2021-10-26
        • 2019-10-09
        • 2016-05-22
        • 2017-07-21
        相关资源
        最近更新 更多