kubectl patch'ing keys containing forward slash
I wanted to use kubectl to (JSON) patch an Ingress. The value needing patching is an annotation tailscale.com/funnel.
TL;DR The Stack overflow answer has the solution: replace
/with~1
With apologies for using YAML instead of JSON:
Ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
tailscale.com/funnel: "true"
The solution becomes:
VALUE="true" # Or "false"
# Pretty-printed for clarity
PATCH="
[
{
'op':'replace',
'path':'/metadata/annotations/tailscale.com~1funnel',
'value':'${VALUE}'
}
]"
kubectl patch ingress/${INGRESS} \
--namespace=${NAMESPACE} \
--context=${CONTEXT} \
--type=json \
--patch="${PATCH}"