I want to edit a Kubernetes Ingress configuration and add/replace some data inside the file using a linux command, as i am writing a shell script.
The command i have to use is :
kubectl edit svc -n istio-system istio-ingressgateway
The command opens up a VI editor and i need to replace some lines to achieve my setup, and i want to write a shell command that opens up, appends and saves into it.
CodePudding user response:
I assume that you want to change the image name in yaml file.
You can use the "sed" command
sed 's/old_text/new_text/g' /path/to/file.yaml
This is the way if you are using the shell script. But if you are using any programming language you can also parse the yaml file like json.
CodePudding user response:
you can use the kubectl patch.
if there is a simple change, for example, change patching loadBalancerIP
kubectl patch services itom-cdf-ingress-frontend-svc -p '{"spec":{"type":"LoadBalancer","loadBalancerIP": "EXTERNAL-IP"}}' -n core
if there are some nested or complex changes, you can use also JSON
file as well.
kubectl patch ingress some-ingress --type json -p "$(cat test-patch.json)"
# test-patch.json
[{
"op": "add",
"path": "/spec/rules/-",
"value": {
"host": "www.svc.domain.com",
"http": {
"paths": [
{
"backend": {
"serviceName": "svc-name",
"servicePort": 80
}
}
]
}
}
}]