<p>so I've got a Kubernetes cluster where I set up a deployment with two pods. In one pod, there is a MySQL container running and in another pod an Ubuntu container. In the Ubuntu container, I want to execute a Python script, that connects to the MySQL container.</p>
<p>But when I try to connect to the other pod, it says:</p>
<pre><code>mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'mysql-service:3306' (111 Connection refused)
</code></pre>
<p>My service looks like this:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysql-service
  labels:
    app: mysql-db-app
spec:
  selector:
    app: mysql-db-app
  ports:
    - port: 3306
      targetPort: 3306
</code></pre>
<p>This is my mysql-deployment.yaml:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    io.kompose.service: mysql-db-app
  name: mysql-db-app
spec:
  selector:
    matchLabels:
      io.kompose.service: mysql-db-app
  strategy: {}
  template:
    metadata:
      labels:
        io.kompose.service: mysql-db-app
    spec:
      containers:
      - image: mysql:8
        name: mysql-db-app
        env:
          - name: MYSQL_ROOT_PASSWORD
            value: root
        ports:
          - containerPort: 3306
        volumeMounts:
        - mountPath: /var/lib/mysql
          name: mysql-data
      volumes:
      - name: mysql-data
        persistentVolumeClaim:
          claimName: mysql-pvc
      restartPolicy: Always
</code></pre>
<p>Do you know how to solve this problem?</p>

johnsonhudson
<p>Looks like there is an issue with the label selector.
Update your service to this</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysql-service
  labels:
    io.kompose.service: mysql-db-app
spec:
  selector:
    io.kompose.service: mysql-db-app
  ports:
    - port: 3306
      targetPort: 3306
</code></pre>
<p>The service label selector should match with the label selectors defined in deployment.yaml</p>
