【问题标题】:GKE node with modprobe带有 modprobe 的 GKE 节点
【发布时间】:2019-07-08 09:10:14
【问题描述】:

有没有办法在启动/升级节点后或在 GKE 中自动加载任何内核模块(在我的例子中是“modprobe nfsd”)?我们在我们的 kubernetes 集群上运行 NFS 服务器 pod,每次 GKE 升级后它都会死掉

cos和ubuntu镜像都试过了,好像都没有默认加载nfsd。

也尝试过这样的事情,但它似乎没有做它应该做的事情:

kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
  name: nfsd-modprobe
  labels:
    app: nfsd-modprobe
spec:
  template:
    metadata:
      labels:
        app: nfsd-modprobe
    spec:
      hostPID: true
      containers:
        - name: nfsd-modprobe
          image: gcr.io/google-containers/startup-script:v1
          imagePullPolicy: Always
          securityContext:
            privileged: true
          env:
          - name: STARTUP_SCRIPT
            value: |
              #! /bin/bash

              modprobe nfs
              modprobe nfsd
              while true; do sleep 1; done

【问题讨论】:

    标签: kubernetes google-kubernetes-engine nfs


    【解决方案1】:

    我遇到了同样的问题,现有答案是正确的,我想用 kubernetes 集群中的 nfs pod 的工作示例来扩展它,它具有加载所需模块的功能和库。

    它有两个重要的部分:

    • 特权模式
    • 在容器内挂载/lib/modules目录以使用它

    nfs-server.yaml

    kind: Pod
    apiVersion: v1
    metadata:
      name: nfs-server-pod
    spec:
      containers:
        - name: nfs-server-container
          image: erichough/nfs-server
          securityContext:
            privileged: true
          env:
          - name: NFS_EXPORT_0
            value: "/test *(rw,no_subtree_check,insecure,fsid=0)"
          volumeMounts:
          - mountPath: /lib/modules # mounting modules into container
            name: lib-modules
            readOnly: true # make sure it's readonly
          - mountPath: /test
            name: export-dir
      volumes:
      - hostPath: # using hostpath to get modules from the host
          path: /lib/modules
          type: Directory
        name: lib-modules
      - name: export-dir
        emptyDir: {}
    

    参考也有帮助 - Automatically load required kernel modules

    【讨论】:

      【解决方案2】:

      默认情况下,您不能从容器内部加载模块,因为排除内核组件是容器轻量级和可移植性的主要原因之一。您需要从主机操作系统加载模块,以使其在容器内可用。这意味着您只需启动一个脚本,即可在每次 GKE 升级后启用所需的内核模块。

      但是,有一个 somewhat hacky way 可以从 docker 容器中加载内核模块。这一切都归结为以升级的权限和访问某些主机目录的权限启动您的容器。如果你真的想在容器中挂载内核模块,你应该尝试一下。

      【讨论】:

      • 启动脚本的问题是它不能很好地用于自动扩展 GKE 集群。第二个问题是谷歌会定期更新 GKE 节点上的操作系统
      猜你喜欢
      • 2021-04-19
      • 1970-01-01
      • 1970-01-01
      • 2019-08-10
      • 1970-01-01
      • 2017-09-28
      • 2017-10-11
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多