Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

yq replace value in manifest yaml

I have a k8s manifest file for loadbalancer below and cannot for the life of me get the $ipaddress be replaced with value, I have got to to overwrite whole file or part of or even just leave blank. How can I replace only the $ipaddress like in below

Tried as example 2 below:

yq e '.spec|=select(.loadBalancerIP) .ports.port = "172.16.87.98"' manifest.yaml
yq e -i '(.spec|=select(.loadBalancerIP.$ipaddress) = "172.16.87.98"' manifest.yaml
  apiVersion: v1
    kind: Service
    metadata:
      name: my-lb-cluster
    spec:
      loadBalancerIP: $ipaddress
      ports:
        - name: ssl
          port: 8080
      selector:
        role: webserver
      sessionAffinity: None
      type: LoadBalancer

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If the YAML is as simple as in your question, you can use:

yq e -i '.spec.loadBalancerIP = "172.16.87.98"' manifest.yaml

To update manifest.yaml and set .loadBalancerIP inside .spec to "172.16.87.98"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading