<p>I have created mysql k8s container and nodejs k8s container under same namespace.I can't able to connect mysql db.(sequalize)</p>

<p>I have tried to connect using '''<a href="http://mysql.e-commerce.svc.cluster.local:3306" rel="nofollow noreferrer">http://mysql.e-commerce.svc.cluster.local:3306</a>'''.But i got "SequelizeHostNotFoundError" error. </p>

<p>Here is my service and deployment yaml files.</p>

<pre><code>kind: Service
metadata:
 labels:
   app: mysql
 name: mysql
 namespace: e-commerce
spec:
  type: NodePort
  ports:
  - port: 3306
    targetPort: 3306
    nodePort: 30306
  selector:
    app: mysql
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mysql
  namespace: e-commerce
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql-container
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim```
</code></pre>

<p>From the ClusterIP worked for me or better way to go with the host name of the local cluster service ex. <code>db-mysql.default.svc.cluster.local</code>. This way if you cluster restarts and your IP changes, then you got it covered. </p>

<p><a href="https://i.stack.imgur.com/x1JIi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x1JIi.png" alt="enter image description here"></a></p>
