curl - 通过rest api创建k8s key 时出错

标签 curl kubernetes kubernetes-secrets

我想通过 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/

相关文章:

php - 如何在 PHP 中复制 cURL 和 python 的 'requests' 库?

macos - 是否可以将 curl 设置为在进度条之前显示文件名?

kubernetes - Kubernetes Pod 之间的通信

kubernetes - Openshift 中的 Cron Job 不是有效模板,而是带有 yml 的 *batch.CronJob

kubernetes - 为所有命名空间创建 secret

linux - 使用 CURL 或 WGET 读取 Gzip 文件页脚

php - 从 phpMyAdmin 导出非常大的表?

kubernetes - 为单个部署禁用Kubernetes中的Crashloop功能-用例:重新加载

docker - Helm 图表使用来自证书管理器的 secret

ssl - 从 secret 创建 OpenShift TLS 路由