<p>i wanted to make wordpress with kubernetes, but wordpress cant use host from mariadb-service. This is my script</p>
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: db-wordpress
  labels:
    app: mariadb-database
spec:
  selector:
    app: mariadb-database
  ports:
  - port: 3306
  clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mariadb-database
spec:
  selector:
    matchLabels:
      app: mariadb-database
  template:
    metadata:
      labels:
        app: mariadb-database
    spec:
      containers:
      - name: mariadb-database
        image: darywinata/mariadb:1.0
        env:
          - name: MYSQL_ROOT_PASSWORD
            valueFrom:
              secretKeyRef:
                name: database-secret
                key: password
          - name: MYSQL_USER
            value: blibli
          - name: MYSQL_PASSWORD
            valueFrom:
              secretKeyRef:
                name: database-secret
                key: password
          - name: MYSQL_DATABASE
            value: wpdb
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                - key: servicetype
                  operator: In
                  values:
                  - database-mariadb
</code></pre>
<p>im already fight this error for 1 week, can somebody help me with this?</p>
<p>note: inside docker container port 3306 is not listening, idk this is wrong or not.</p>

Dary Winata
<p>Hi there and welcome to stackoverflow.</p>
<p>There are two issues with your setup. First of all, I have tried running your mysql docker image locally and compared to the official mysql image it is not listening to any port. Without the mysql process listening to any port, you will not be able to connect to it.</p>
<p>Also, you might want to consider a standard internal service type instead of one with <code>clusterIP: None</code> which is called a headless service and usually used for statefulsets and not deployments. more information can be found <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="nofollow noreferrer">on the official documentation</a></p>
<p>So in order to connect from your application to your pod:</p>
<ol>
<li>Fix problem with your custom mysql image so it actually listens on port 3306 (or whatever you have configured in your image)</li>
</ol>
