通过 rest 创建 k8s secret 时出错 api

Error while creating k8s secret through rest api

我想通过 kubectl 创建一个 secret api。 下面是脚本,我是 运行 但在解析 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"}
}

成功了。