简体   繁体   English

无法将卷装入 kube.netes 中的 pod

[英]Unable to mount a volume into a pod in kubernetes

I have a pod, which is querying an AWS service using Boto.我有一个 pod,它正在使用 Boto 查询 AWS 服务。 This pod runs in kube.netes cluster in EKS.此 pod 在 EKS 中的 kube.netes 集群中运行。

When running on a real cluster, we use ServiceAccount/Role/RoleBinding to give the Pod permission to acquire an IAM role.在真实集群上运行时,我们使用 ServiceAccount/Role/RoleBinding 来授予 Pod 获取 IAM 角色的权限。

But when I run it locally, using kind , I want it to use credentials that are in my ~/.aws directory.但是当我使用kind在本地运行它时,我希望它使用我的~/.aws目录中的凭据。

So I mount the volumes as follows:所以我按如下方式安装卷:

    volumes:
    - hostPath:
        path: /var/run/datadog
        type: ""
      name: dsdsocket
    - hostPath:
        path: /Users/me/.aws
        type: DirectoryOrCreate
      name: aws

And use them in the pod as follows:并在 pod 中使用它们,如下所示:

      volumeMounts:
      - mountPath: /var/run/datadog
        name: dsdsocket
        readOnly: true
      - mountPath: /root/.aws
        name: aws
        readOnly: true

I have checked that there are credentials in ~/.aws/credentials我检查过~/.aws/credentials

But the directory just shows up as empty inside the pod:但是该目录在 pod 中显示为空:

root@the_pod:/app# ls -al /root/.aws
total 8
drwxr-xr-x 2 root root 4096 Apr 12 19:33 .
drwx------ 1 root root 4096 May  9 17:22 ..

NOTE: I have tried mounting the actual credentials file in ~/.aws/credentials too, but it doesnt mount either.注意:我也尝试在~/.aws/credentials中安装实际的凭证文件,但它也没有安装。

Any ideas what i am doing wrong?任何想法我做错了什么?

I guess you need to use extra mounts while creating the kind cluster, it is used to pass through storage on the host to a kind node for persisting data, mounting through code, etc.我想您在创建 kind 集群时需要使用 额外的挂载,它用于将主机上的存储传递到 kind 节点以持久保存数据、通过代码挂载等。

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  # add a mount from /path/to/my/files on the host to /files on the node
  extraMounts:
  - hostPath: /path/to/my/files/
    containerPath: /files
    # optional: if set, the mount is read-only.
    # default false
    readOnly: true
    propagation: HostToContainer

Creating a kind cluster with a custom config file:使用自定义配置文件创建种类集群:

$ kind create cluster --config=kind-config.yaml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM