Wordpress and mysql pod rollout correct but wordpress not showing up on my browser

11/1/2020

I'm beginner to K8s so please bear with me.

I've rollout a wordpress with a mysql using Kubernetes. The rollout has completed and is running on my machine using minikube.

However, the thing is wordpress is not showing up on my browser

These are my pods

mysql291020-68d989895b-vxbwg 1/1 Running 0 18h

wp291020-7dccd94bd5-dfqqn 1/1 Running 0 19h

These are my services

mysql291020-68d989895b-vxbwg 1/1 Running 0 18h

wp291020-7dccd94bd5-dfqqn 1/1 Running 0 19h

After some thoughts, I thought it maybe related to how I setup my service for wordpress (see code below).

apiVersion: v1
kind: Service
metadata:
  name: wp291020
  labels:
    app: wp291020
spec:
  ports:
    - port: 80
  selector:
    app: wp291020
    tier: frontend
  type: LoadBalancer

Not sure if it is the right place to look at. I'm adding below my deployement for the wordpress, and also the service for mysql and the deployment for mysql, in case it is needed.

deployment for wordpress

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wp291020
spec:
  selector:
    matchLabels:
      app: wp291020
  replicas: 1
  template:
    metadata:
      labels:
        app: wp291020
    spec:
      containers:
      - name: wp-deployment
        image: andykwo/test123:wp_291020
        ports:
        - containerPort: 80
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html    
      volumes:
      - name: wordpress-persistent-storage
        emptyDir: {}

service for mysql

apiVersion: v1
kind: Service
metadata:
  name: mysql291020
  labels:
    app: mysql291020
spec:
  ports:
    - port: 3306
  selector:
    app: mysql291020
    tier: mysql
  clusterIP: None

deployment for mysql

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql291020
spec:
  selector:
    matchLabels:
      app: mysql291020
  replicas: 1
  template:
    metadata:
      labels:
        app: mysql291020
    spec:
      containers:
      - env:
        - name: MYSQL_DATABASE
          value: wordpress
        - name: MYSQL_PASSWORD
          value: my_wordpress_db_password
        - name: MYSQL_ROOT_PASSWORD
          value: my_wordpress_db_password
        - name: MYSQL_USER
          value: wordpress        
        name: db
        image: andykwo/test123:wp_291020
        ports:
        - containerPort: 3306
        volumeMounts:
        - name: db-data
          mountPath: /var/lib/mysql    
      volumes:
      - name: db-data
        emptyDir: {}

Just to mention that the docker containers are functionning also correctly when running only on the containers but I do have access to the wordpress through my browser.

I can provide my docker compose yaml if asked.

Thank you.

PS: I'm adding my docker compose file, in case

version: '3.3'

services:
   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     volumes:
       - wordpress_files:/var/www/html
     ports:
       - "80:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: my_wordpress_db_password

   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: my_db_root_password
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: my_wordpress_db_password
volumes:
    wordpress_files:
    db_data:
-- Andy K
docker
kubernetes
mysql
wordpress

2 Answers

11/1/2020

To access the frontend from your web browser, you can port-forward the service to your local machine.

kubectl port-forward svc/wp291020 80:80

If you are using a cloud system with an external IP, you would need to verify that IP address is getting attached to your service, as shown here

-- Ben W
Source: StackOverflow

11/2/2020

If you're using Minikube you can easily expose your frontend Deployment via Service of a type NodePort or LoadBalancer. As Minikube is unable to create a real load balancer it uses for it NodePort under the hood anyway.

So if you exposed your wp291020 Deployment via wp291020 Service you can get its URL by typing:

minikube service wp291020 --url

and it will show you something like in the example below:

http://172.17.0.15:31637

I'm wondering if you have any good reason for clusterIP: None in your Service definition. mysql291020 Deployment is exposed within your kubernets cluster to your frontend Pods via Service which type is ClusterIP (if you don't specify the type explicitely, by default ClusterIP is created) so it should have its Cluster IP to be accessible by frontend Pods. I think you can simply get rid of clusterIP: None line in your mysql291020 Service definition. What you have in your example is called headless service with selector but I guess there is no real need for it in your case.

-- mario
Source: StackOverflow