How to append tolerations as dictionary in the yaml file

Опубликовано: 26 Май 2026
на канале: Emrah KAYA
No
0

Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram:   / ky.emrah  

Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!How to append tolerations as dictionary in the yaml file

I have a YAML file which creates Daemonset in the kubernetes cluster but there's no toleration block in the code which doesn't guarantee to create the daemonset for spot instances. That is why I need to append tolerations after a certain string before deploying the YAMl file through Pipeline.
The Sample YAML is as follow
apiVersion: v1
items:
apiVersion: apps/v1
kind: DaemonSet
metadata:
annotations:
deprecated.daemonset.template.generation: "4"
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apps/v1","kind":"DaemonSet","metadata":{"annotations":{},"name":"twistlock-defender-ds","namespace":"twistlock"},"spec":{"selector":{"matchLabels":{"app":"twistlock-defender"}},"template":{"metadata":{"annotations":{"container.apparmor.security.beta.kubernetes.io/twistlock-defender":"unconfined"},"labels":{"app":"twistlock-defender"}},"spec":{"containers":[{"env":[{"name":"WS_ADDRESS","value":"wss://us-east1.cloud.twistlock.com:443"},{"name":"DEFENDER_TYPE","value":"cri"},{"name":"LOG_PROD","value":"true"},{"name":"SYSTEMD_ENABLED","value":"false"},{"name":"DOCKER_CLIENT_ADDRESS","value":"/var/run/docker.sock"},{"name":"DEFENDER_CLUSTER_ID","value":"b86802a4-e576-393f-8f52-c90ae7764796"},{"name":"DEFENDER_CLUSTER","value":"AZJAPNJE01KUB12991DV01"},{"name":"MONITOR_SERVICE_ACCOUNTS","value":"true"},{"name":"MONITOR_ISTIO","value":"false"},{"name":"COLLECT_POD_LABELS","value":"true"},{"name":"INSTALL_BUNDLE","value":"eyJzZWNyZXRzIjp7fSwiZ2xvYmFsUHJveHlPcHQiOnsiaHR0cFByb3h5IjoiIiwibm9Qcm94eSI6IiIsImNhIjoiIiwidXNlciI6IiIsInBhc3N3b3JkIjp7ImVuY3J5cHRlZCI6IiJ9fSwiY3VzdG9tZXJJRCI6InVzLTItMTU4Mjg4NjU5IiwiYXBpS2V5IjoiT0JBVU5hTmFSZ29ZQTB4YmpMUVl4cGlDd0wraU9LZXZqbnhUUW5JYjQ3eFh0U3cwSStTelZ6WDdIeVp0cDNBOWdrRVBvNjhMZURFeXpTai95L2NvSnc9PSIsIm1pY3Jvc2VnQ29tcGF0aWJsZSI6ZmFsc2V9"},{"name":"HOST_CUSTOM_COMPLIANCE_ENABLED","value":"false"},{"name":"CLOUD_HOSTNAME_ENABLED","value":"false"},{"name":"FIPS_ENABLED","value":"false"}],"image":"registry-auth.twistlock.com/tw_o0bftrujy5daxq309xzzdpwtmbbbexix/twistlock/defender:defender_32_00_159","name":"twistlock-defender","resources":{"limits":{"cpu":"900m","memory":"512Mi"},"requests":{"cpu":"256m"}},"securityContext":{"capabilities":{"add":["NET_ADMIN","NET_RAW","SYS_ADMIN","SYS_PTRACE","SYS_CHROOT","MKNOD","SETFCAP","IPC_LOCK"]},"privileged":true,"readOnlyRootFilesystem":true},"volumeMounts":[{"mountPath":"/var/lib/twistlock","name":"data-folder"},{"mountPath":"/var/lib/twistlock/certificates","name":"certificates"},{"mountPath":"/var/run","name":"docker-sock-folder"},{"mountPath":"/etc/passwd","name":"passwd","readOnly":true},{"mountPath":"/dev/log","name":"syslog-socket"},{"mountPath":"/var/lib/containers","name":"cri-data"},{"mountPath":"/run","name":"runc-proxy-sock-folder"}]}],"dnsPolicy":"ClusterFirstWithHostNet","hostNetwork":true,"hostPID":true,"restartPolicy":"Always","serviceAccountName":"twistlock-service","volumes":[{"name":"certificates","secret":{"defaultMode":256,"secretName":"twistlock-secrets"}},{"hostPath":{"path":"/dev/log"},"name":"syslog-socket"},{"hostPath":{"path":"/var/lib/twistlock"},"name":"data-folder"},{"hostPath":{"path":"/etc/passwd"},"name":"passwd"},{"hostPath":{"path":"/var/run"},"name":"docker-sock-folder"},{"hostPath":{"path":"/var/lib/containers"},"name":"cri-data"},{"hostPath":{"path":"/run"},"name":"runc-proxy-sock-folder"}]}}}}
creationTimestamp: "2023-02-22T02:46:26Z"
Source of the question:
https://stackoverflow.com/questions/7...

Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/