I am working on something similar that I hope it helps:
When you start a pod on statefulset you can retrieve the DNS local with an internal shell and showing the host file, like the following:
% kubectl exec custom-infinispan-0 -it -- sh
sh-4.4$ cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
10.xxx.xx.xx stafulset-0.<your-service>.default.svc.cluster.local statefulset-0
In case of infinispan you need to load the proper query as -D parameter using JAVA_OPTS.
Something like the following can be used:
apiVersion: v1
kind: ConfigMap
metadata:
name: <your-thingie>-infinispan
data:
INFINISPAN_CACHE_STATISTICS: "true"
USER: "admin"
DB_ADDR: "mariadb"
DB_PORT: "3306"
DB_USER: "<>"
DB_DATABASE: "<>"
JAVA_OPTIONS: "-Dinfinispan.cluster.stack=k8s -Djgroups.dns.query=<your-thingie>-infinispan.default.svc.cluster.local"
The big deal is that you will need to generate your custom container, because infinispan does not allways include the configurations for the cluster stack. You can find them at https://github.com/infinispan/infinispan/tree/main/core/src/main/resources/default-configs
If you need more info about your resolution you can also execute the following:
% kubectl describe svc <your-service-name>