Home > Net >  Wordpress mysql helm deployment
Wordpress mysql helm deployment

Time:05-10

Learning kubernetes, docker and helm; I am diving into a Devops programm, and have been asked to deploy a wordpress mysql with helm at my internship enterprises. Tried to do something but the wordpress is unable to connect to the database and i think the database is not able to write to the mounted nfs volume path; really need help and explanation if possible.. tried everything i saw but did not work.

The error i have from wordpress in web browser is Error connecting to databases

Here is my project manifest files, pods status

Service.yaml

apiVersion: v1
kind: Service
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  ports:
   - port: 3306
     name: wordpress-mysql
     protocol: TCP
  selector:
    app: wordpress
    tier: mysql
  type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  ports:
    - port: 80
      name: wordpress
      nodePort: 32000
  selector:
    app: wordpress
    tier: frontend
  type: NodePort

Deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: mysql
    spec:
      containers:
      - image: bitnami/mysql
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: root
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-pvc
          mountPath: "/var/lib/mysql"
      volumes:
      - name: mysql-pvc
        persistentVolumeClaim:
          claimName: mysql-pvc

---
apiVersion: apps/v1
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:5.8-apache
        name: wordpress
        env:
        - name: WORDPRESS_DB_HOST
          value: wordpress-mysql
        - name: WORDPRESS_DB_NAME
          value: wordpressdb
        - name: WORDPRESS_DB_PASSWORD
          value: test123
        ports:
        - containerPort: 80
          name: wordpress
        volumeMounts:
        - name: wordpress-pvc
          mountPath: "/var/www/html"
      volumes:
      - name: wordpress-pvc
        persistentVolumeClaim:
          claimName: wordpress-pvc

Pods status

NAME                                   READY   STATUS    RESTARTS   AGE
pod/wordpress-fcf86fbd9-q9csh          1/1     Running   0          34h
pod/wordpress-mysql-6dfb484d54-wrlnm   1/1     Running   0          34h


NAME                      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
service/kubernetes        ClusterIP   10.96.0.1             443/TCP        9d
service/wordpress         NodePort    10.98.97.25           80:32000/TCP   34h
service/wordpress-mysql   ClusterIP   10.97.50.98           3306/TCP       34h


NAME                              READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/wordpress         1/1     1            1           34h
deployment.apps/wordpress-mysql   1/1     1            1           34h

NAME                                         DESIRED   CURRENT   READY   AGE
replicaset.apps/wordpress-fcf86fbd9          1         1         1       34h
replicaset.apps/wordpress-mysql-6dfb484d54   1         1         1       34h

Thank in advance for your help. Really need it

CodePudding user response:

Check out your DB password and WordPress connection password that you are adding into for connection both are different, ideally, it should be the same.

MYSQL_ROOT_PASSWORD : root but WORDPRESS_DB_PASSWORD: test123 try with updating the password for Wordpress so it can connect to MySQL.

WORDPRESS_DB_NAME you have created this DB into MySQL or just adding name ? directly ? it could be due to Wordpress finding for that db and you have not created it. try following this official tut and check once as it is : https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/ it's mostly same only

  • Related