Kubernetes wordpress to mysql connection issue

8/2/2019

I have a Wordpress pod that doesn't connect to my SQL DB pod. The wordpress mysql deployment is called wordpress-mysql so the referencing is correct. This is the message that appears.

Complete! WordPress has been successfully copied to /var/www/html

Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22

Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22

MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known

This is the code for the wordpress.yaml file:

apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  selector:

    app: wordpress
  ports:
  - name: web
    port: 80
    targetPort: 80


---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: wp-pv-claim
  labels:
    app: nginx
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: do-block-storage


---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: frontend
spec:
  rules:
  - host: test.example.services
    http:
      paths:
      - path: /
        backend:
          serviceName: frontend
          servicePort: web

---



---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: frontend
    spec:
      containers:
      - image: wordpress:4.8-apache
        name: wordpress
        env:
        - name: WORDPRESS_DB_HOST
          value: wordpress-mysql
        - name: WORDPRESS_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 80
          name: wordpress
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html
      volumes:
      - name: wordpress-persistent-storage
        persistentVolumeClaim:
          claimName: wp-pv-claim

The following is an output from kubectl get services

NAME              TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
frontend          ClusterIP   10.245.131.56   <none>        80/TCP     4m25s
kubernetes        ClusterIP   10.245.0.1      <none>        443/TCP    9m46s
wordpress-mysql   ClusterIP   None            <none>        3306/TCP   5m16s

MySQL Service YAML:

apiVersion: v1
kind: Service
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  ports:
    - port: 3306
  selector:
    app: wordpress
    tier: mysql
  clusterIP: None
-- Rutnet
kubernetes
kubernetes-ingress
traefik

0 Answers