I have this ingress object where I am trying to patch the 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
I would like to update the secret name using kubectl patch
I have tried:
$ kubectl patch ing hello-world -p '{"spec":{"tls":{"secretName":"updated"}}}'
Error from server: cannot restore slice from map
and:
$ 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 {}
Any suggestions?
tls
is an array/slice so you have to refer to it like that and include it in the original patch.
$ kubectl patch ing hello-world -p '{"spec":{"tls":[{"hosts":["my.host"], "secretName": "updated"}]}}'
A good way to get the -p
s right (that works for me) is to convert them from YAML to JSON. You can try an online tool like this.
You can update above json array field with following
kubectl patch ing hello-world --type json -p '[{"op": "replace", "path": "/spec/tls/0/secretName", "value" : "updated"}]'
Here, you have to specify the index, in your case it is 0