使用
sed
,您可以在 livenessProbe
之前插入一段文本,如下所示:
sed -e '/livenessProbe/i\
volumes:\n- name: my-agent\n persistentVolume:\n claimName: my-agent
' sample.yaml
如果
sample.yaml
是
resources:
limits:
cpu: 500m
memory: 2Gi
requests:
cpu: 100m
memory: 512Mi
livenessProbe:
httpGetPath: /heartbeat
结果将是:
resources:
limits:
cpu: 500m
memory: 2Gi
requests:
cpu: 100m
memory: 512Mi
volumes:
- name: my-agent
persistentVolume:
claimName: my-agent
livenessProbe:
httpGetPath: /heartbeat
如果要添加的代码块位于 yaml 文件中
addons.yaml
:
sed -e "/livenessProbe/i\
$(cat addons.yaml | sed ':a;N;$!ba;s/\n/\\n/g')
" sample.yaml