Error when using the NodeJs and sed to create the new Kubernetes config file

4/19/2019

I am using the Shelljs and sed command to generate the new K8S config file

shell.exec(`sed -e s%${server}%${endpoint}%g -e s%${certificate}%${cert}%g config-temp`)
shell.exec("cat config-temp | tee config")

Then I am checking if the K8S cluster is working by running

kubectl cluster-info

The error message looks like

error: Error loading config file "~/.kube/config": yaml: control characters are not allowed

However, if I copy all the content from the config-temp, then paste it into the config, kubectl cluster-info works.

I haven't found same error messages above online. I am just wondering if anyone come across the similar issue. Any helpers

-- Akira
kubernetes
node.js
sed
shelljs

2 Answers

4/20/2019

Thanks for you guys input. the sed part has no problem, I guess I haven't phased my problem clear enough. The problem is when I replace the certificate with cert, the text in the cert variable has some special characters , which cannot be recognized by K8S.

-- Akira
Source: StackOverflow

4/19/2019

try sed -Ei instead of sed -e, really edit the config-temp

--
Source: StackOverflow