<p>i have a Kubernetes cluster on Azure, in that i have created MySQL pod and Django pod. I have exposed MySQL pod as service and trying to connect from Django. I have given service name in settings.py file in Django and tried to run "runserver" then i am getting below error. </p>

<p>OperationalError: (2003, "Can't connect to MySQL server on 'mysqlserv' (111)").</p>

<p>If i try to connect with "mysql" command then it is working. Below is the command i used.</p>

<p>"mysql -h mysqlerv -u root -p".</p>

<p>But surprisingly, if i give Mysql pod IP in /etc/hosts file(like 10.144.1.5  mysqlserv) of Django pod then "runserver" is working. </p>

<p>Can someone help me to connect Django pod with mysql pod over service (cluster IP)..</p>

<p>Below is my sql-server yaml file. </p>

<pre><code>apiVersion: v1 
kind: Pod
metadata:
  name: sqlpod
  labels:
    app: demo
    env: test
spec:
  containers:
    - name: sqlapp-tester-custom
      image: mydockerregistry.com/mysql:5.7
      env:
        - name: SQL_HOST_NAME
          value: sqlapp-tester-custom
        - name: MYSQL_DATABASE
          value: myapp1_db
        - name: MYSQL_ROOT_PASSWORD
          value: myownPassword123
      ports:
        - name: sqlport
          containerPort: 3306
          protocol: TCP
      volumeMounts:
        - name: azurefile
          mountPath: /sql_data
  volumes:
    - name: azurefile
      azureFile:
        secretName: myazure-secret-name
        shareName: my_azure_file_share_name
        readOnly: false
</code></pre>

Paramesh
<p>clusterip will change if pod restart or recreate it's better to use service name.</p>

<p>Kubernetes Services : <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/</a></p>

<p>you can check mysql running example : <a href="https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/</a></p>

<p>example service yaml: </p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None
</code></pre>

<p>I do recommend to check this example once Mysql with wordpress: <a href="https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/" rel="nofollow noreferrer">https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/</a></p>
