I remember there used to ways to turn off the creation of .DS_Store but they removed it, I can't figure out for life why they would make such a change. I had to write a program [0] to watch the entire file system and delete .DS_Store as soon as they're created. [0] https://github.com/slmjkdbtl/dskill
You can turn it off for network volumes: defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE https://support.apple.com/en-us/102064 I don't recall there ever being a way to turn it off for local volumes.
It seems to be the first time I'm seeing Apple themselves officially recommending a "defaults write" command.