Tools such as pssh (parallel ssh, https://github.com/robinbowes/pssh), pdsh (https://github.com/chaos/pdsh), or clusterssh (https://github.com/duncs/clusterssh) allow you to issue commands simultaneously to multiple servers at once. Out of all of them, pssh is the easiest to install.
pssh is listed in the APT registry, so we can simply update the registry cache and install it:
$ sudo apt update
$ sudo apt install pssh
This will actually install pssh under the name parallel-ssh; this was done to avoid conflict with the putty package.
We can now use kubectl get nodes to programmatically get the IPs of all nodes in the cluster, and pass it to parallel-ssh:
$ parallel-ssh --inline-stdout --user root --host "$(kubectl get nodes -o=jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}')" -x "-o StrictHostKeyChecking=no" "sysctl -w vm.max_map_count=262144 && ulimit -n 65536"
[1] 23:27:51 [SUCCESS] 142.93.126.236
vm.max_map_count = 262144
[2] 23:27:51 [SUCCESS] 142.93.113.224
vm.max_map_count = 262144
...
We are setting the ssh parameter StrictHostKeyChecking to no to temporarily disable ssh checking the authenticity of the nodes. This is insecure but offers convenience; otherwise, you'll have to add each node's key to the ~/.ssh/known_hosts file.