使用主机路径与Kind Kubernetes群集共享本地目录 [英] Share local directory with Kind Kubernetes Cluster using hostpath
问题描述
我想与同类集群共享我的非空本地目录.
I want to share my non-empty local directory with kind cluster.
基于此处的答案:如何以Kind(在docker中为kubernetes)引用本地卷
我尝试了以下几种变化:
I tried few variations of the following:
种类群集Yaml:
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraMounts:
- hostPath: /Users/xyz/documents/k8_automation/data/manual/
containerPath: /host_manual
extraPortMappings:
- containerPort: 30000
hostPort: 10000
Pod yaml:
apiVersion: v1
kind: Pod
metadata:
name: manual
spec:
serviceAccountName: manual-sa
containers:
- name: tools
image: tools:latest
imagePullPolicy: Never
command:
- bash
tty: true
volumeMounts:
- mountPath: /home/jenkins/agent/data
name: data
volumes:
- name: data
hostPath:
path: /host_manual
type: Directory
---
我看到在创建pod时目录/home/jenkins/agent/data确实存在.但是,该文件夹为空.
I see that the directory /home/jenkins/agent/data does exist when the pod gets created. However, the folder is empty.
此处的种类文档: https://kind.sigs. k8s.io/docs/user/configuration/#extra-mounts
应该是这样的情况:群集yaml中extraMounts中主机路径(/Users/xyz/documents/k8_automation/data/manual/)上本地计算机中的任何内容都可用于容器路径(/host_manual)上的节点,然后将其安装在容器卷mounthPath(/home/jenkins/agent/data).
It should be the case that whatever is in the local machine at hostpath (/Users/xyz/documents/k8_automation/data/manual/) in extraMounts in the cluster yaml be available to the node at containerPath (/host_manual), which then gets mounted at container volume mounthPath (/home/jenkins/agent/data).
我应该补充一点,即使我将群集yaml文件中的hostPath更改为不存在的文件夹,也会将空的数据"更改为文件夹仍然安装在容器中,所以我认为这是从本地群集到同类群集的连接.
I should add that even if I change the hostPath in the cluster yaml file to a non-existent folder, the empty "data" folder still gets mounted in the container, so I think it's the connection from my local to kind cluster that's the issue.
- 为什么我没有得到/Users/xyz/documents/k8_automation/data/manual/的内容,并且容器中的/home/jenkins/agent/data也有很多文件?
- 我该如何解决?
- 如果没有解决办法,还有其他选择吗?
推荐答案
结果证明这些yaml配置很好.
Turns out these yaml configuration was just fine.
目录未显示在容器中的原因与docker设置有关.而且,由于种类是使用Docker容器节点"运行本地Kubernetes集群的工具",因此很重要.
The reason the directory was not showing up in the container was related with docker settings. And because "kind is a tool for running local Kubernetes clusters using Docker container "nodes"", it matters.
似乎docker限制了资源共享,并且默认情况下仅允许将特定目录绑定安装到Docker容器中.添加特定目录后,我想将其显示在容器中的偏好设置"->目录"下的目录列表中.资源->文件共享,行之有效!
It seems docker restricts resource sharing and allows only specific directories to be bind mounted into Docker containers by default. Once I added the specific directory I wanted to show up in the container to the list of directories under Preferences -> Resources -> File sharing, it worked!
这篇关于使用主机路径与Kind Kubernetes群集共享本地目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!