你好,我是无羡,你也可以叫我Hinsteny·Hisoka.
今天在这里,我想带大家一起通过实践Kind文件挂载这件事情,给大家分享一下自己遇到开源技术产品的使用问题时,用怎样的思路和方式去解决会比较高效且正确!
参与云原生网关Higress项目的过程中,领到了一个能够支持在本地对WasmPlugin直接进行e2e测试的任务。
tips: Higress是阿里牵头开源的一款新一代云原生网关产品,而且其支持WasmPlugin对其能力进行扩展;
这里不讨论Higress和WasmPlugin相关的内容,对上面的任务进行概括,即为:
在本地使用Kind创建一个k8s集群,然后再将本地构建出来的WasmPlugin挂载到Higress的gateway-Pod上面,这样就能直接访问Higress-gateway,对WasmPlugin的能力进行验证。
由于我们知道使用Kind创建的k8s集群中的Node是一个虚拟的Docker-Container,即Pod都是部署在这个虚拟Node上的,因此我们需要先将LocalPath挂载到虚拟Node上,然后Pod再挂载Node上的Path,才能实际访问到LocalPath的内容,具体事项如下:
参考Kind官方文档–Extra Mounts,因此我的配置文件如下,
# cluster.conf
kind: Cluster
apiVersion: kind.x-www.hack95.com/v1alpha4
nodes:
- role: control-planekubeadmConfigPatches:- |kind: InitConfigurationnodeRegistration:kubeletExtraArgs:node-labels: "ingress-ready=true"extraPortMappings:- containerPort: 80hostPort: 80protocol: TCP- containerPort: 443hostPort: 443protocol: TCPextraMounts:# 这里不能写死,需要动态指定,因为每个人的本地路径不一样- hostPath: /Users/h/workspace/project/higress/pluginscontainerPath: /opt/plugins
首先仔细阅读了官方文档,没有关于动态传参的说明,那就去Github问问呗
Issue: 如何动态传参对配置进行进行配置呢?
最后得到结论:
不支持,也不打算支持。
其实通过2的确认后,接下来就是我们如何自己动态生成配置文件了,那办法就有很多,我们可以根据所处的不同的集成、测试环境分别给出方案;这里通过shell动态输出配置文件,
PROJECT_DIR=$(pwd)cat < "tools/hack/cluster.conf"# cluster.conf
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-planekubeadmConfigPatches:- |kind: InitConfigurationnodeRegistration:kubeletExtraArgs:node-labels: "ingress-ready=true"extraPortMappings:- containerPort: 80hostPort: 80protocol: TCP- containerPort: 443hostPort: 443protocol: TCPextraMounts:- hostPath: ${PROJECT_DIR}/pluginscontainerPath: /opt/plugins
EOF
kind create cluster --config=tools/hack/cluster.conf
Pod的Storage方案有很多,继续看K8S官方文档-- volumes;
上面我们将本地的plugins目录,已经挂载到了Node的’/opt/plugins’,那Pod的就更简单了,如下
apiVersion: v1
kind: Pod
metadata:name: test-pd
spec:containers:- image: www.hack95.com/test-webservername: test-containervolumeMounts:# directory location on pod- mountPath: /opt/pod/pluginsname: test-volumevolumes:- name: test-volumehostPath:# directory location on host--Nodepath: /opt/plugins# this field is optionaltype: Directory
针对开源技术产品的使用问题,首先读官方文档,然后在社区找帮助,参与开源项目的都是一群很nice的小伙伴!