IP address of pod (mysql) keep changing

I have a application running on my k3s cluster which consist of the app itself and a mysql database.
The problem is when of the nodes restarted and the database moves to another node, the ip address of the database changes. That mean i can no longer access the app unless i figure out the new ip address of the database and edit the configuration file of the app with the new ip address .

Anyone knows how to solve this? My MySQL database is running as a statefulset. The app is running as a deployment.

Pods get a random IP and change every time they are replaced. You make a service that selects those pods to give another app a stable name/IP to talk to it.

can you explain a little bit more what i should do?
In cluster explorer i select services and create a service, but that didn’t help
Maybe i did it wrong.

@tando it is better not to use IP addresses to connect to other pods in a k8s cluster. the cluster itself provides canonical dns names for pods and services, as described here: DNS for Services and Pods | Kubernetes as you have noticed and as @vincent has confirmed (and as can be easily observed), a pod gets assigned a new IP address each time it is recreated (basically on each restart of the deployment, as this leads to recreation of the pod(s)). Typically, rancher creates a service for each deployment, so you should connect to my-deployment.my-namespace.svc.cluster.local .

Thanks for your answer.
It is not that i want the application to connect to an IP address. The application is built that way. When you first start the application, it will ask you to fill in the user, password and IP address of the database. When you do that correctly the application will start up. It would be nice if instead of filling in the user, password and IP address, i could fill the host-name of the database to make the corresponding connection. Then it doesn’t matter which IP address the database has.

why not set the address of the database to a static url using ingress? i do this with my mongodb. Alternatively set a ConfigMap like below

apiVersion: v1
kind: ConfigMap
metadata:
  name: mongodb-configmap
  namespace: mongo
data:
  database_url: mongodb-service <--set this to the name of your service file

then in your deployment file for your app set an env var

- name: ME_CONFIG_MONGODB_SERVER
            valueFrom:
              configMapKeyRef:
                name: mongodb-configmap
                key: database_url

now every time the pod reruns you won’t have to change around the IP

Thanks for your advise and help. To be honest i am new to Kubernetes so i have to figure out how to do this and where, but i will give it a try.
I hear that is not recommended to use static urls in Kubernetes. I don’t know if this is true.