如何将用于连接 docker 注册表的 bash 命令转换为 yaml 配置文件?
·
回答问题
按照本教程将本地 docker 注册表连接到 KIND 集群,bash 脚本中有以下代码块。我想使用我的配置文件,但我不知道下面的块如何适应(语法中有很多破折号和管道)。
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
endpoint = ["http://${reg_name}:${reg_port}"]
EOF
我的配置文件:
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 8080
hostPort: 80
protocol: TCP
- role: worker
- role: worker
- role: worker
- role: worker
Answers
在您显示的 shell 片段中,第一行和最后一行之间的所有内容,包括破折号和管道,都是有效的 YAML 文件; shell 所做的唯一处理是将${reg_name}和${reg_port}替换为相应环境变量的值。
如果您想将其与现有的种类配置文件合并,您应该能够只组合顶级键:
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
et: cetera
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"]
endpoint = ["http://kind-registry:5000"]
如果您有其他containerdConfigPatches,则每行以-开头的项目序列是一个 YAML 列表(就像您在nodes:中一样),您可以将此补丁添加到列表的末尾。 (这有点不太可能,因为这个选项没有记录在种类的配置文档中。)
更多推荐
所有评论(0)