zoukankan      html  css  js  c++  java
  • 03-利用flexVolume挂载cifs目录

    本文介绍如何利用 flexVolume 挂载 windows share folder,k8s集群通过rke搭建

    flexVolume

    FlexVolume 是一个自 1.2 版本(在 CSI 之前)以来在 Kubernetes 中一直存在的 out-of-tree 插件接口。 它使用基于 exec 的模型来与驱动程序对接。 用户必须在每个节点(在某些情况下是主节点)上的预定义卷插件路径中安装 FlexVolume 驱动程序可执行文件。

    Pod 通过 flexvolume in-tree 插件与 Flexvolume 驱动程序交互。 更多详情请参考这里

    juliohm/cifs

    基于 Flexvolume 的卷插件,可以让集群挂载 CIFS volumes (samba shares),详见这里

    使用方法

    1. 在每台 node 节点安装依赖 cifs-utils,用于挂载共享目录

      sudo apt-get install -y cifs-utils

    2. 在每台 node 节点安装 juliohm/cifs 插件

    这里可以利用 DaemonSet 来自动部署到 node:

    git clone https://github.com/juliohm1978/kubernetes-cifs-volumedriver.git
    cd kubernetes-cifs-volumedriver
    
    make install
    

    pod 会挂载 node 的 /usr/libexec/kubernetes/kubelet-plugins/volume/exec/ 目录并将文件复制过去

    测试

    apiVersion: v1
    kind: Pod
    metadata:
      name: busybox
      namespace: default
    spec:
      nodeSelector:
        mediatek/role: app
      containers:
      - name: busybox
        image: busybox
        command:
          - sleep
          - "3600"
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - name: test
          mountPath: /data
      volumes:
      - name: test
        flexVolume:
          driver: "juliohm/cifs"
          fsType: "cifs"
          options:
            opts: username=[user_name],password=[pass_word],domain=[domain],file_mode=0755,dir_mode=0755
            server: [ip_or_host_name]
            share: [share_folder]
    

    隐藏敏感信息

    实际使用时,不应将 username password 等敏感信息直接放在 opts 中,可以放在 secret 中:

    ---
    apiVersion: v1
    data:
      password: dXNlcjEyMw==
      username: cGFzczEyMw==
    kind: Secret
    metadata:
      name: my-secret
    type: juliohm/cifs
    
    ---
    ...
        options:
          opts: domain=Foo
          server: 10.0.0.114
          share: /publico
        secretRef:
          name: my-secret
    

    debug

    实际使用时,遇到一些问题:

    1. volume无法mount,describe pod 发现报错:Timeout expired waiting for volumes to attach

    ps. 用rke升级k8s到1.17.x之后,会打印更详细的提示:

    Unable to attach or mount volumes: unmounted volumes=[xxx], unattached volumes=[xxx default-token-rcxrw]: failed to get Plugin from volumeSpec for volume "xxx" err=no volume plugin matched

    打印 kubelet container 的 log,提示无法找到插件,enable-controller-attach-detach: false以及 extra_binds: - "/usr/libexec/kubernetes/kubelet-plugins:/var/lib/kubelet/volumeplugins" 都设定过,并且检查 pod 中插件目录确实存在,这个问题困扰了我很久。

    最后再仔细看 flexvolume 的文档,找到这样一段话

    The default plugin directory is /usr/libexec/kubernetes/kubelet-plugins/volume/exec/. It can be changed in kubelet via the --volume-plugin-dir flag, and in controller manager via the --flex-volume-plugin-dir flag.

    注意这里提到的插件目录是 /usr/libexec/kubernetes/kubelet-plugins/volume/exec/而非 /var/lib/kubelet/volumeplugins,然后尝试给 kubelet 传递启动参数:

    services:
      kubelet:
        extra_args:
          volume-plugin-dir: /var/lib/kubelet/volumeplugins/volume/exec
    

    重启 kubelet 之后搞定!

  • 相关阅读:
    FLINK 设计文档
    prometheus-dashboard-to-grafana
    apache-flink-training-metrics-monitoring
    多个inputstream的情况下,watermark的值怎么赋值? kakfa中多个partition提取 watermark
    how-apache-flink-enables-new-streaming-applications-part-1
    Advanced DataStream API Low-latency Event Time Join
    checkpoint and savepoint in FlinK
    Flink connectedstreams
    FLINK 案例分析
    Apache 流框架 Flink,Spark Streaming,Storm对比分析(一)
  • 原文地址:https://www.cnblogs.com/windchen/p/12760718.html
Copyright © 2011-2022 走看看