Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yq replace value in manifest yaml

Tags:

yq

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
like image 858
DeclanG Avatar asked Dec 21 '25 08:12

DeclanG


1 Answers

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".

like image 177
0stone0 Avatar answered Dec 24 '25 00:12

0stone0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!