<p>I have a Kube manifest that need be applied to a couple of kubernetes clusters with different resource settings. For that I need to change resource section of this file on the fly. Here's its contents:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: abc-api
  labels:
    app: abc-api
spec:
  ports:
  - name: http
    port: 80
    targetPort: 3000
  - name: https
    port: 3000
    targetPort: 3000
  selector:
    app: abc-api
    tier: frontend
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: abc-api
  labels:
    app: abc-api
spec:
  selector:
    matchLabels:
      app: abc-api
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: abc-api
        tier: frontend
    spec:
      containers:
      - image: ABC_IMAGE
        resources:
          requests:
            memory: "128Mi"
            cpu: .30
          limits:
            memory: "512Mi"
            cpu: .99
</code></pre>

<p>I searched and found that yq is a better tool for this. However when I read values from this file, it only shows it till the line with <strong>'3 dashes'</strong>: no values past that.</p>

<pre><code># yq r worker/deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  name: hometales-api
  labels:
    app: hometales-api
spec:
  ports:
  - name: http
    port: 80
    targetPort: 3000
  - name: https
    port: 3000
    targetPort: 3000
  selector:
    app: hometales-api
    tier: frontend
</code></pre>

<p>I want to read the <strong>Deployment section</strong>, as well as edit the resource values.</p>

<p>Section to read:</p>

<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:

....
</code></pre>

<p>Section to edit:</p>

<pre><code>resources:
  requests:
    memory: "128Mi"
    cpu: .20
  limits:
    memory: "512Mi"
    cpu: .99
</code></pre>

<p>So 1st part of Q: how to read after 2nd instance of 3-dashes?
2nd part of Q: how to edit resource values on the fly?</p>

<p>I'm able to run this command and read this section, but can't read memory or cpu value further:</p>

<pre><code># yq r -d1 deployment.yaml "spec.template.spec.containers[0].resources.requests"
memory: "128Mi"
cpu: .20
</code></pre>

SS-eth0
<p>Use the <code>-d</code> CLI option. See <a href="https://mikefarah.gitbook.io/yq/commands/write-update#multiple-documents" rel="nofollow noreferrer">https://mikefarah.gitbook.io/yq/commands/write-update#multiple-documents</a> for more details.</p>

<p>Also Kubernetes has its own thing for in <code>kubectl patch</code>.</p>
