我正在使用 k3d 运行本地 Kubernetes 并使用 k3d 创建集群。
现在我想将本地目录挂载为持久卷。
我知道在 minikube 中你可以做到:
$ minikube start --mount-string="$HOME/go/src/github.com/nginx:/data" --mount
然后,如果您使用
/data
将 hostPath
安装到 Pod 中,您将把本地目录数据获取到 Pod 中。
k3d中有类似的技术吗?
根据此 Github 问题的答案,您正在寻找的功能尚不可用。
以下是此链接的一些想法:
我想最简单的就是拥有一个包含所有代码的非常通用的安装,例如就我而言,我可以执行
来获取所有代理节点中存在的主机上的所有存储库,以用于热重载。k3d cluster create -v "$HOME/git:/git@agent:*"
根据this文档,可以使用以下带有适当标志的命令:
k3d cluster create NAME -v [SOURCE:]DEST[@NODEFILTER[;NODEFILTER...]]
此命令将卷安装到节点中
(Format:[SOURCE:]DEST[@NODEFILTER[;NODEFILTER...]]
示例:
`k3d cluster create --agents 2 -v /my/path@agent:0,1 -v /tmp/test:/tmp/other@server:0`
这里也是一篇有趣的文章,介绍卷和存储在 K3s 集群中如何工作(带有示例)。
我认为此功能尚不可用 https://github.com/k3d-io/k3d/issues/566
到目前为止,我们只能在创建新集群时挂载volumn。
k3d cluster create mykube --volume HOME/go/src/github.com/nginx:/data
根据官方文档(如果您使用配置文件),我们需要设置
volume
标志,如下所示-
apiVersion: k3d.io/v1alpha5 # this will change in the future as we make everything more stable
kind: Simple # internally, we also have a Cluster config, which is not yet available externally
metadata:
name: cluster-a # name that you want to give to your cluster (will still be prefixed with `k3d-`)
servers: 1 # same as `--servers 1`
agents: 3 # same as `--agents 2`
kubeAPI: # same as `--api-port myhost.my.domain:6445` (where the name would resolve to 127.0.0.1)
host: "local.my.domain.com" # important for the `server` setting in the kubeconfig
hostIP: "127.0.0.1" # where the Kubernetes API will be listening on
hostPort: "6445" # where the Kubernetes API listening port will be mapped to on your host system
image: rancher/k3s:latest # same as `--image rancher/k3s:v1.20.4-k3s1`
network: local-net # same as `--network my-custom-net`
volumes: # repeatable flags are represented as YAML lists
- volume: /home/CORP/DockerEnv/K3S/clusterA/nodevolume/:/data # same as `--volume '/my/host/path:/path/in/node@server:0;agent:*'`
nodeFilters:
- server:0
- agent:*
ports:
- port: 8080:80 # same as `--port '8080:80@loadbalancer'`
nodeFilters:
- loadbalancer
options:
k3d: # k3d runtime settings
wait: true # wait for cluster to be usable before returning; same as `--wait` (default: true)
timeout: "60s" # wait timeout before aborting; same as `--timeout 60s`
disableLoadbalancer: false # same as `--no-lb`
disableImageVolume: false # same as `--no-image-volume`
disableRollback: false # same as `--no-Rollback`
loadbalancer:
configOverrides:
- settings.workerConnections=2048
k3s: # options passed on to K3s itself
extraArgs: # additional arguments passed to the `k3s server|agent` command; same as `--k3s-arg`
- arg: "--cluster-cidr=10.42.0.0/16"
nodeFilters:
- server:*
- arg: "--service-cidr=10.43.0.0/16"
nodeFilters:
- server:*
- arg: "--service-node-port-range=30000-31367"
nodeFilters:
- server:*
nodeLabels:
- label: node=worker # same as `--k3s-node-label 'foo=bar@agent:1'` -> this results in a Kubernetes node label
nodeFilters:
- agent:*
- label: node=master # same as `--k3s-node-label 'foo=bar@agent:1'` -> this results in a Kubernetes node label
nodeFilters:
- server:*
kubeconfig:
updateDefaultKubeconfig: true # add new cluster to your default Kubeconfig; same as `--kubeconfig-update-default` (default: true)
switchCurrentContext: true # also set current-context to the new cluster's context; same as `--kubeconfig-switch-context` (default: true)
runtime: # runtime (docker) specific options
ulimits:
- name: nofile
soft: 26677
hard: 26677