如何在Kind中引用本地卷(Docker中的Kubernetes) [英] How to reference a local volume in Kind (kubernetes in docker)
问题描述
我想设置一个持久卷(pv和pvc),由同类群集中的Pod共享/a>.但是我也需要将数据持久保存在便携式计算机(主机服务器)中,因此卷的路径应该是便携式计算机中的某个东西,我可以直接访问它.
I'd like to set a Persistent Volume (pv and pvc), shared by pods in Kind cluster. But I need to keep the data persisted in my laptop (host server) as well, so the volume's path should be something in my laptop, which I can directly access it.
如果删除同类群集,则该卷应保留而不被销毁.
If I delete the kind cluster, the volume should be persisted, not be destroyed.
我希望可以轻松地在该卷中添加或更新该卷,或者从主机笔记本电脑中复制文件.
I hope to easily add or update in that volume or copy files out of it from my host laptop.
如何让KIND集群中的Pod知道它?
How can I let the pods know it in KIND cluster?
粘贴我的 kind.yaml
供您参考
$ kind
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker
推荐答案
When you create your kind cluster you can specify host directories to be mounted on a virtual node. If you do that, then you can configure volumes with hostPath
storage, and they will refer to the mount paths on the node.
因此,您将创建一个种类的配置文件:
So you would create a kind config file:
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
extraMounts:
- hostPath: /home/bill/work/foo
containerPath: /foo
然后运行
kind create cluster --config kind-config.yaml
创建集群.
在您的Kubernetes YAML文件中,您需要将该 containerPath
挂载为主机路径",在节点上.广告连播规范可能部分包含:
In your Kubernetes YAML file, you need to mount that containerPath
as a "host path" on the node. A pod spec might contain in part:
volumes:
- name: foo
hostPath:
path: /foo # matches kind containerPath:
containers:
- name: foo
volumeMounts:
- name: foo
mountPath: /data # in the container filesystem
请注意,此设置非常特定于种类.通常,主机路径不是可靠的存储:您无法控制将Pod安排在哪个节点上,并且Pod和节点都可以在实际集群中被删除.在某些托管设置(AWS EKS,Google GKE)中,您可能根本无法控制主机内容.
Note that this setup is extremely specific to kind. Host paths aren't reliable storage in general: you can't control which node a pod gets scheduled on, and both pods and nodes can get deleted in real-world clusters. In some hosted setups (AWS EKS, Google GKE) you may not be able to control the host content at all.
您可以重新访问应用程序设计,以最大程度地减少对文件"的需求.作为一流的对象.与其更新音量",不如说更新音量".考虑部署具有更新内容的新Docker映像;而不是复制文件"考虑可以通过入口控制器公开的HTTP服务.
You might revisit your application design to minimize the need for "files" as first-class objects. Rather than "update the volume" consider deploying a new Docker image with updated content; rather than "copy files out" consider an HTTP service you can expose through an ingress controller.
这篇关于如何在Kind中引用本地卷(Docker中的Kubernetes)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!