Kubectl 补丁给出:来自服务器的错误:无法从地图恢复切片

u12*_*123 4 kubernetes kubectl

我有这个入口对象,我正在尝试修补secretName

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-world
...
spec:
  rules:
  - host: my.host
    http:
      paths:
      - backend:
          serviceName: hello-world
          servicePort: 8080
  tls:
  - hosts:
    - my.host
    secretName: my-secret
Run Code Online (Sandbox Code Playgroud)

我想使用kubectl patch我尝试过的方法更新秘密名称:

$ kubectl patch ing hello-world -p '{"spec":{"tls":{"secretName":"updated"}}}'
Error from server: cannot restore slice from map
Run Code Online (Sandbox Code Playgroud)

和:

$ kubectl patch ing hello-world -p '[{"op": "replace", "path": "/spec/tls/secretName", "value" : "updated"}]'
Error from server (BadRequest): json: cannot unmarshal array into Go value of type map[string]interface {}
Run Code Online (Sandbox Code Playgroud)

有什么建议么?

Ric*_*ico 5

tls是一个数组/切片,因此您必须像这样引用它并将其包含在原始补丁中。

$ kubectl patch ing hello-world -p '{"spec":{"tls":[{"hosts":["my.host"], "secretName": "updated"}]}}'
Run Code Online (Sandbox Code Playgroud)

获得-p正确的 s 的一个好方法(对我有用)是将它们从 YAML 转换为 JSON。您可以尝试这样的在线工具。