<p>I try to deploy wordpress/mysql in kubernetes.
I want mysql and wordpress to use different volumes. I'm trying to write nfs for wordpress and hostpath for mysql.</p>
<p>But wordpress and mysql are not connected. I don't know why. I'd appreciate your help.</p>
<p>here's my code:
Mysql.yaml</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  containers:
  - name: mysql
    image: mysql:5.7
    ports:
    - containerPort: 3306
      protocol: TCP
    env:
    - name: MYSQL_ROOT_PASSWORD
      value: qwer1234
    volumeMounts:
      - name: mysql-volume
        mountPath: /var/lib/mysql
  volumes:
      - name: mysql-volume
        persistentVolumeClaim:
          claimName: mysql-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-svc
  labels:
    app: mysql
spec:
  type: ClusterIP
  selector:
    app: mysql
  ports:
    - protocol: TCP
      port: 3306
      
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  volumeName: mysql-pv
​
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /vol/mysql
</code></pre>
<hr />
<p>wordpress.yaml</p>
<pre><code>apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  replicas: 2
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      containers:
      - image: wordpress
        name: wordpress
        env:
        - name: WORDPRESS_DB_HOST
          value: mysql:3306
        - name: WORDPRESS_DB_PASSWORD
          value: P@ssw0rd
        volumeMounts:
        - mountPath: /nfs-volume/html
          name: wordpress-pv
        ports:
          - protocol: TCP
            containerPort: 80
      volumes:
      - name: wordpress-pv
        persistentVolumeClaim:
          claimName: wordpress-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: wordpress-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
  volumeName: wordpress-pv
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: wordpress-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  nfs:
    server: 192.168.201.11
    path: /nfs-volume
---
apiVersion: v1
kind: Service
metadata:
  name: wordpress-svc
  labels:
    app: wordpress
spec:
  type: LoadBalancer
  selector:
    app: wordpress
  ports:
    - protocol: TCP
      port: 80
</code></pre>

koleli
<p>you have provided the port number at last in environment variable</p>
<p>please try with out it</p>
<pre><code>env:
        - name: WORDPRESS_DB_HOST
          value: mysql:3306
</code></pre>
<p>instead use this</p>
<pre><code>env:
        - name: WORDPRESS_DB_HOST
          value: MySQL
</code></pre>
<p>you can check the example at : <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>
<p>if you read the documentation of Docker image they are also providing the host name without the port as value.</p>
<p>also in Wordpress environment you have to pass the MySQL password which you are passing wrong</p>
<pre><code>- name: WORDPRESS_DB_PASSWORD
          value: P@ssw0rd
</code></pre>
<p>instead it should be</p>
<pre><code>- name: WORDPRESS_DB_PASSWORD
          value: qwer1234
</code></pre>
