<p>I have this ingress object where I am trying to patch the <code>secretName</code>:</p>

<pre><code>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
</code></pre>

<p>I would like to update the secret name using <code>kubectl patch</code> I have tried:</p>

<pre><code>$ kubectl patch ing hello-world -p '{"spec":{"tls":{"secretName":"updated"}}}'
Error from server: cannot restore slice from map
</code></pre>

<p>and:</p>

<pre><code>$ 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 {}
</code></pre>

<p>Any suggestions?</p>

u123
<p><code>tls</code> is an array/slice so you have to refer to it like that and include it in the original patch.</p>

<pre><code>$ kubectl patch ing hello-world -p '{"spec":{"tls":[{"hosts":["my.host"], "secretName": "updated"}]}}'
</code></pre>

<p>A good way to get the <code>-p</code>s right (that works for me) is to convert them from YAML to JSON. You can try an online tool like <a href="https://onlineyamltools.com/convert-yaml-to-json" rel="noreferrer">this</a>.</p>
