如何解决如何转换将docker注册表连接到yaml配置文件的bash命令?
在this tutorial之后,将本地Docker注册表连接到KIND集群,bash脚本中包含以下代码段。我想使用我的配置文件,但是我不知道下面的块是如何适合的(语法中有很多破折号和管道)。
#include <iostream>
#include <string>
using namespace std;
int main(){
int a = 4,b = 8;
//float r = 5.55f;
string s = "comica";
cout << "this is a test and value of surtd is " << a << ".\n and value of sturd is " << b;
cout << ".\n and value of me is " << s;
return 0;
}
我的配置文件:
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
解决方法
YAML中的文档仍然存在问题。尝试使用例如也许是printf
?
printf '%s\n' \
'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}"]' |
kind create cluster --config=-
幸运的是,您的字符串不包含任何单引号,因此我们可以安全地使用这些引号进行换行。同样幸运的是,您的数据不包含任何shell变量扩展或命令替换,因此我们可以使用单引号(引号)。
出于记录目的,如果您需要嵌入文字单引号,
'you can'"'"'t get there from here'
产生带文字的带引号的字符串
you can't get there from here
(仔细观察;这是一个单引号字符串,与双引号文字单引号"'"
相邻,与另一个单引号字符串相邻),并且如果需要扩展变量或命令替换,您将需要将这些字符串切换为双引号。示例:
printf '%s\n' \
'literal $dollar sign in single quotes,the shell won'"'"'t touch it' \
"inside double quotes,$HOME expands to your home directory" \
'you can combine the two,like '"$(echo '"this"')"',too!'
,
在显示的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:
中一样),您可以将此补丁添加到列表的末尾。 (这不太可能发生,因为kind Configuration documentation中没有记录此选项。)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。