我想通过 kubectl api 创建一个 secret 。 下面是脚本,我正在运行,但在解析 yaml 文件时出错。 请帮忙
curl -vk \
-X POST \
-d @- \
-H "Authorization: Bearer $(cat token)" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
https://ip:port/api/v1/namespaces/nginx-ingress/secrets <<'EOF'
{
"apiVersion": "v1",
"kind": "Secret",
"metadata": {
"namespace": "nginx-ingress",
},
"type": "Opaque"
"data": {
"username": "YWRtaW4=",
"password": "MWYyZDFlMmU2N2Rm"
}
EOF
错误:
message": "the object provided is unrecognized (must be of type Secret): couldn't get version/kind; json parse error: invalid character '}' looking for beginning of object key string ({\"apiVersion\": \"v1\",\"kind\": \"S ...)", "reason": "BadRequest",
最佳答案
我更改了 JSON 结构,在其中添加了最后遗漏的大括号和类型键中的一个逗号。
curl -vk \
-X POST \
-d @- \
-H "Authorization: Bearer $(cat token)" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
https://192.168.2.100:6443/api/v1/namespaces/nginx-ingress/secrets <<'EOF'
{
"apiVersion":"v1",
"kind" :"Secret",
"metadata" :{"namespace" :"nginx-ingress","name":"mysecret1"},
"type": "Opaque",
"data": {"username": "YWRtaW4=","password": "MWYyZDFlMmU2N2Rm"}
}
成功了。
关于curl - 通过rest api创建k8s key 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51089657/