Migrate from master-data to master-only nodes


i deployed opensearch using the kubernetes operator.
I started my cluster with master-data nodes, but now i need to grow and i want to move to master only nodes.

just changing the role doesn’t work, as it fails to boot the pod with the error message

Node is started with node.data=false, but has shard data, Use ‘opensearch-node repurpose’ tool to clean up

trying to use the tool from inside the pod fails because , obviously opensearch is running …

what is the best way to migrate then? any idea?

answering myself…

use routing api, where “secure-cluster-masters-0”, “secure-cluster-masters-1” and “secure-cluster-masters-2” are the hostnames of the master nodes

PUT _cluster/settings
    "transient" : {
        "cluster.routing.allocation.exclude._name" : "secure-cluster-masters-0 , secure-cluster-masters-1, secure-cluster-masters-2"

then apply the manifest with the remove data role