WordPress Error establishing a database connection using kubernetes

Solution:1

You need to add targetPort on the mysql service yaml definition.

apiVersion: v1

kind: Service

metadata:

 name: db

 labels:

  name: db-service

  app: demo-wordpress-app

spec: 

 ports: 

  – port: 3306

    targetPort: 3306

 selector:

    name: mysql-app-label

Solution:2

include below line in mysql service YAML

targetPort: 3306