我试图将扩展资源添加到群集中的一个节点。我遵循官方文档中的this任务
我已按照说明进行操作,但PATCH
似乎没有效果。
运行后:
curl --header "Content-Type: application/json-patch+json" --request PATCH --data '[{"op": "add", "path": "/status/capacity/example.com~1dongle", "value": "4"}]' http://localhost:8001/api/v1/nodes/kubernetes-3/status
我得到了回应,并增加了扩展资源
"capacity": {
"cpu": "8",
"example.com/dongle": "4",
"memory": "8218052Ki",
"pods": "110"
},
但是如果我运行kubectl describe node kubernetes-3
,容量将具有旧值:
Capacity:
cpu: 8
memory: 8218052Ki
pods: 110
我已经检查了apiserver日志,一切看起来都很好:
PATCH /api/v1/nodes/kubernetes-3/status: (39.112896ms) 200 [[curl/7.59.0] 127.0.0.1:49234]
但是,如果我使用kubectl patch
命令,该命令将返回node "kubernetes-3" not patched
我运行的命令:kubectl patch node kubernetes-3 --type='json' -p '[{"op": "add", "path": "/status/capacity/example.com~1dongle", "value": "4"}]'
同样,apiserver日志显示响应成功(状态200
):
PATCH /api/v1/nodes/kubernetes-3: (4.831866ms) 200 [[kubectl/v1.8.0+coreos.0 (linux/amd64) kubernetes/a65654e] 127.0.0.1:50004]
kubectl版本输出:
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0+coreos.0", GitCommit:"a65654ef5b593ac19fbfaf33b1a1873c0320353b", GitTreeState:"clean", BuildDate:"2017-09-29T21:51:03Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0+coreos.0", GitCommit:"a65654ef5b593ac19fbfaf33b1a1873c0320353b", GitTreeState:"clean", BuildDate:"2017-09-29T21:51:03Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
答案 0 :(得分:0)
我已经在Kubernetes集群v1.11.1上尝试过
Curl版本工作正常,但是需要一些时间(5-10秒)才能在“ get”输出中显示它:
curl --header "Content-Type: application/json-patch+json" \
--request PATCH \
--data '[{"op": "add", "path": "/status/capacity/example.com~1dongle", "value": "2"}]' \
http://localhost:8001/api/v1/nodes/node-name/status
kubectl get node node-name -o yaml
...
capacity:
cpu: "2"
ephemeral-storage: 20263528Ki
example.com/dongle: "2"
example2.com/dongle: "4"
example3.com/dongle: "4"
example4.com/dongle: "4"
hugepages-1Gi: "0"
hugepages-2Mi: "0"
memory: 7652316Ki
pods: "110"
...
kubectl版本仍然无法正常工作,但是我想这是因为它请求了错误的地址/api/v1/nodes/node-name
,而不是/api/v1/nodes/node-name/status
命令
kubectl -v=9 patch node/node-name --type='json' -p='[{"op": "add", "path": "/status/capacity/example.com-dongle", "value": "6"}]'
给我日志:
I0803 13:08:38.552155 694 round_trippers.go:386] curl -k -v -XPATCH -H“接受:应用程序/ json” -H“内容类型:应用程序/ json-patch + json” -H“用户代理:kubectl / v1.11.1 (linux / amd64)kubernetes / b1b2997“ 'https://10.156.0.8:6443/api/v1/nodes/node-name'
如果我们在kubeclt代理连接上检查了类似的请求:
它不起作用:
curl -XPATCH -H "Accept: application/json" -H "Content-Type: application/json-patch+json" -H "User-Agent: kubectl/v1.11.1 (linux/amd64) kubernetes/b1b2997" --data '[{"op": "add", "path": "/status/capacity/example4.com~1dongle", "value": "4"}]' \
'http://127.0.0.1:8001/api/v1/nodes/node-name'
但是最后加上“ / status”效果很好:
curl -XPATCH -H "Accept: application/json" -H "Content-Type: application/json-patch+json" -H "User-Agent: kubectl/v1.11.1 (linux/amd64) kubernetes/b1b2997" --data '[{"op": "add", "path": "/status/capacity/example4.com~1dongle", "value": "4"}]' \
'http://127.0.0.1:8001/api/v1/nodes/node-name/status'