can’t access to mysql via phpmyadmin in 2 separates dockers

I have two dockers, a phpmyadmin and a mysql, all in a minikube cluster.

I want to be able to access mysql via phpmyadmin but I have an error.

2020-12-13 9:09:49 9 [Warning] IP address ‘172.18.0.1’ could not be resolved: Name does not resolve
2020-12-13 9:09:49 9 [Warning] Aborted connection 9 to db: ‘unconnected’ user: ‘unauthenticated’ host: ‘172.18.0.1’ (This connection closed normally without authentication)

When I go on my mysql container with docker exec -it, I can access mysql via
mysql -u root -p -h localhost (and no password)
But if I try to access it by specifying host 172.18.0.1 (to simulate the connection from phpmyadmin) via mysql -u root -p -h 172.18.0.1 I get this error :

ERROR 2002 (HY2000): Can’t connect to MySQL server on ‘172.18.0.1’ (115)

….

Here are my yaml configurations of phpmyadmin and mysql :

mysql :

apiVersion: v1
kind: Service
metadata:
  labels:
    app: mysql
  name: mysql
spec:
  ports:
  - port: 3306
    protocol: TCP
    targetPort: 3306
  selector:
    app: mysql

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app: mysql
  name: mysql-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

---

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: mysql
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: service_mysql
        imagePullPolicy: Never
        name: mysql
        ports:
        - name: mysql
          containerPort: 3306
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-pvc

phpmyadmin :

apiVersion: v1
kind: Service
metadata:
  labels:
    app: phpmyadmin
  name: phpmyadmin
  annotations:
    metallb.universe.tf/allow-shared-ip: shared
spec:
  type: LoadBalancer
  loadBalancerIP: 172.17.0.2
  ports:
  - name: phpmyadmin
    port: 5000
    protocol: TCP
    targetPort: 5000
  selector:
    app: phpmyadmin
  type: LoadBalancer

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: phpmyadmin
  labels:
    app: phpmyadmin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: phpmyadmin
  template:
    metadata:
      labels:
        app: phpmyadmin
    spec:
      containers:
      - name: phpmyadmin
        image: service_phpmyadmin
        imagePullPolicy: Never
        ports:
        - containerPort: 5000
        env:
        - name: PMA_HOST
          value: mysql
        - name: PMA_PORT
          value: '3306'
        - name: PMA_USER
          value: root
        - name: MYSQL_ROOT_PASSWORD
          value: ''

Tell me if you need more files! Thanks guys !

Source: Docker Questions