简体   繁体   English

Kubectl修补程序和curl修补程序无法修补资源

[英]Kubectl patch and curl patch unable to patch a resource

I tried to add an extended resource to one node in my cluster. 我试图将扩展资源添加到群集中的一个节点。 I followed this task, from official documentation 我跟着这个任务,从官方文档

I've followed the instructions step by step, but the PATCH doesn't seem to have an effect. 我已按照说明逐步进行操作,但是PATCH似乎没有效果。

After running: 运行后:

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

I get a response, with added extended resource 我得到回应,并添加了更多资源

"capacity": {
  "cpu": "8",
  "example.com/dongle": "4",
  "memory": "8218052Ki",
  "pods": "110"
},

But if I run kubectl describe node kubernetes-3 the capacity has old values: 但是,如果我运行kubectl describe node kubernetes-3则容量具有旧值:

Capacity: cpu: 8 memory: 8218052Ki pods: 110

I've checked the apiserver logs and everything looks good: 我检查了apiserver日志,一切看起来都不错:

PATCH /api/v1/nodes/kubernetes-3/status: (39.112896ms) 200 [[curl/7.59.0] 127.0.0.1:49234]

However, if I use the kubectl patch command, the command returns node "kubernetes-3" not patched 但是,如果我使用kubectl patch命令,该命令将返回node "kubernetes-3" not patched

The command I ran: kubectl patch node kubernetes-3 --type='json' -p '[{"op": "add", "path": "/status/capacity/example.com~1dongle", "value": "4"}]' 我运行的命令: kubectl patch node kubernetes-3 --type='json' -p '[{"op": "add", "path": "/status/capacity/example.com~1dongle", "value": "4"}]'

And again, the apiserver logs, which show, that the response was successful (status 200 ): 再次,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 version output: 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"}

I've tried it on the Kubernetes cluster v1.11.1 我已经在Kubernetes集群v1.11.1上尝试过

Curl version is working fine, but it takes some time (5-10 seconds) to show it on the "get" output: 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 version still doesn't work, but I guess it's because it requests the wrong address /api/v1/nodes/node-name , instead of /api/v1/nodes/node-name/status kubectl版本仍然无法正常工作,但是我想这是因为它请求的地址是错误的/api/v1/nodes/node-name ,而不是/api/v1/nodes/node-name/status

The command 命令

kubectl -v=9 patch node/node-name --type='json' -p='[{"op": "add", "path": "/status/capacity/example.com-dongle", "value": "6"}]'

gave me the log: 给了我日志:

I0803 13:08:38.552155 694 round_trippers.go:386] curl -k -v -XPATCH -H "Accept: application/json" -H "Content-Type: application/json-patch+json" -H "User-Agent: kubectl/v1.11.1 (linux/amd64) kubernetes/b1b2997" ' https://10.156.0.8:6443/api/v1/nodes/node-name ' I0803 13:08:38.552155 694 round_trippers.go:386] curl -k -v -XPATCH -H“ Accept:application / json” -H“ Content-Type:application / json-patch + json” -H“ User-Agent :kubectl / v1.11.1(linux / amd64)kubernetes / b1b2997“' https://10.156.0.8:6443/api/v1/nodes/node-name '

If we check the similar request on kubeclt proxy connection: 如果我们在kubeclt代理连接上检查类似的请求:

It doesn't work: 它不起作用:

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' 

But with “/status” in the end it works well: 但是最后使用“ / 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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM