Reputation: 113
When I want to run the following YAML file, I get the following error: error converting YAML to JSON: yaml: line 30: found unknown escape character
kind: Deployment
apiVersion: apps/v1beta2
metadata:
labels:
run: $DEPLOYMENT_NAME
name: $DEPLOYMENT_NAME
namespace: default
spec:
replicas: 2
revisionHistoryLimit: 10
selector:
matchLabels:
run: $TEMPLATE_LABEL
template:
metadata:
labels:
run: $TEMPLATE_LABEL
spec:
containers:
- name: wapp
image: $IMAGE_WCE
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "sed -i $a\-Djdk.tls.rejectClientInitiatedRenegotiation=true /opt/app/a.ini"]
I think it is the command caused the error.
sed -i $a\\-Djdk.tls.rejectClientInitiatedRenegotiation=true /opt/app/a.ini
Upvotes: 9
Views: 17270
Reputation: 3059
You have to add an additional \
character to escape \
in command. Also, replace $
values in your manifest. Btw, the file has only 25 lines.
command: ["/bin/sh", "-c", "sed -i $a\\-Djdk.tls.rejectClientInitiatedRenegotiation=true /opt/app/a.ini"]
$ cat deploy.yml
kind: Deployment
apiVersion: apps/v1beta2
metadata:
labels:
run: busybox
name: busybox
namespace: default
spec:
replicas: 2
revisionHistoryLimit: 10
selector:
matchLabels:
run: busybox
template:
metadata:
labels:
run: busybox
spec:
containers:
- name: wapp
image: busybox
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "sed -i $a\\-Djdk.tls.rejectClientInitiatedRenegotiation=true /opt/app/a.ini"]
$ kubectl apply -f deploy.yml
deployment.apps/busybox created
Upvotes: 4
Reputation: 506
I think the problem is the \-
in your sed command.
Just looking at the yaml spec, if you use double-quotes you have to escape the backslash, ie: \\-
but what about using single-quotes?
Upvotes: 22