Я пытаюсь создать Pod в Kubernetes, используя curl
.
Это YAML:
cat > nginx-pod.yaml <<EOF
apiVersion: v1
kind: Pod
metadata:
name: nginx1
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
EOF
У меня есть токен с разрешениями на это, и я написал следующую команду curl
:
curl -k -v -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json;charset=utf-8' https://127.0.0.1:6443/api/v1/namespaces/default/pods --data '{"name":"","namespace":"default","content":"apiVersion: v1\nkind: Pod\nmetadata:\n name: nginx1\nspec:\n containers:\n - name: nginx\n image: nginx:1.7.9\n ports:\n - containerPort: 80\n","validate":true}'
Что должно бытьэквивалентно nginx-pod.yaml
файлу.
YAML в порядке, потому что когда я запускаю kubectl create -f nginx.pod.yaml
, он его создает.
Но когда я пытался запустить его с curl
, я получал:
< Content-Length: 617
<
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "Pod \"\" is invalid: [metadata.name: Required value: name or generateName is required, spec.containers: Required value]",
"reason": "Invalid",
"details": {
"kind": "Pod",
"causes": [
{
"reason": "FieldValueRequired",
"message": "Required value: name or generateName is required",
"field": "metadata.name"
},
{
"reason": "FieldValueRequired",
"message": "Required value",
"field": "spec.containers"
}
]
},
"code": 422
* Connection #0 to host 127.0.0.1 left intact
Я пытался изменить Content-Type
на Content-type: text/x-yaml
, но это не помогло.
Есть идеи, в чем может быть причина?
Одна из ошибок связана с полем «metadata.name».