I have setup the Kubernetes cluster on google cloud with 2 nodes. as everything works fine except the Wordpress.
A brief about Setup and what I am trying to do.
I am trying to run laravel, WordPress and mysql containers. so far laravel and mysql is working fine and accessible. but having issue with Wordpress. everytime when i try to access wordpress it always gets redirected to https://k8s.example.com/wp-admin/setup-config.php and css also missing it's shows mixed content issue when i check browser > inspect > console when i try to browser any css url manually it redirect to the setup-config.php again like https://k8s.example.com/wp-includes/js/jquery/jquery.js?ver=1.12.4-wp it will again take to https://k8s.example.com/wp-admin/setup-config.php in short anything i am browsering it redirect to the setup-config.php as i have create info.php file and try to access with https://k8s.example.com/info.php it's also taking to setup-config.php
i am using following images:
wordpress :- wordpress:php7.4-fpm-alpine
laravel :- custom build image using Dockerfile
mysql :- mysql:5.7
nginx :- nginx:alpine
I am using NFS to handling the code and that is working fine. I can see files on the NFS server properly.
here is Nginx config below
# /etc/nginx/conf.d/default.conf
server {
listen 80;
root /var/www/html/app/public;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass laravel-service-port:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffers 256 128k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
include fastcgi_params;
}
}
server {
listen 81;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass wordpress-service:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffers 256 128k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
include fastcgi_params;
}
}
i have connected both with php-fpm using their serivce names in fastcgi_pass and opened laravel port on 80 and wordpress port on 81 and opened both the port in nginx deployment using containerPort.
then created a service with type ClusterIP here is file content below.
apiVersion: v1
kind: Service
metadata:
name: application-webserver-service
spec:
type: ClusterIP
selector:
component: frontend
ports:
- name: laravel
targetPort: 80
port: 80
- name: wordpress
targetPort: 81
port: 81
Then here is ingress files for both.
# laravel-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
spec:
tls:
- secretName: k8s-example-tls
hosts:
- k8s.example.com
rules:
- host: k8s.example.com
http:
paths:
- path: /laravel(/|$)(.*)
backend:
serviceName: application-webserver-service
servicePort: 80
I have read the docs to implement annotations. as this laravel is not and issue it's working fine. just mentioned making it clear about the setup
# wordpress-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: wordpress-ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
spec:
tls:
- secretName: k8s-example-tls
hosts:
- k8s.example.com
rules:
- host: k8s.example.com
http:
paths:
- path: /
backend:
serviceName: application-webserver-service
servicePort: 81
Here I am getting an issue with Wordpress. I have tried to make true both the SSL related annotations still the redirection happening.
I have tried with the method I have used in laravel like making path with /wordpress(/|$)(.*) and rewrite-target/$2 but same thing happening.
before both the config YAML are in one file then I separated them just to make it more clear and to implement the redirection rules properly so laravel rules don't have an issue with WordPress working.
Hope i explained it properly but still if there is any part missing please let me know.
Thank you
EDIT 1
# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/application-nginx-loadbalancer-5d8c58775-fdx9t 1/1 Running 0 27m
pod/application-test-deployment-65bf678959-cm2dd 1/1 Running 0 27m
pod/mysql-deployment-instance-6dff9dcb6b-n9qwk 1/1 Running 0 27m
pod/nginx-ingress-controller-6456bbf68-db6pn 1/1 Running 0 3h17m
pod/nginx-ingress-default-backend-674d599c48-fc689 1/1 Running 0 3h17m
pod/wordpress-deployment-79849f7497-jzmhc 1/1 Running 0 27m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/application-service-port ClusterIP 10.0.15.193 <none> 9000/TCP 27m
service/application-webserver-service ClusterIP 10.0.5.90 <none> 80/TCP,81/TCP 27m
service/kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 6d1h
service/mysql-service-instace ClusterIP 10.0.15.54 <none> 3306/TCP 27m
service/nginx-ingress-controller LoadBalancer 10.0.8.169 192.168.1.1 80:30327/TCP,443:31217/TCP 6d1h
service/nginx-ingress-default-backend ClusterIP 10.0.10.103 <none> 80/TCP 6d1h
service/redis-service-instace ClusterIP 10.0.5.9 <none> 6379/TCP 27m
service/wordpress-service ClusterIP 10.0.7.197 <none> 9000/TCP 27m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/application-nginx-loadbalancer 1/1 1 1 27m
deployment.apps/application-test-deployment 1/1 1 1 27m
deployment.apps/mysql-deployment-instance 1/1 1 1 27m
deployment.apps/nginx-ingress-controller 1/1 1 1 6d1h
deployment.apps/nginx-ingress-default-backend 1/1 1 1 6d1h
deployment.apps/wordpress-deployment 1/1 1 1 27m
NAME DESIRED CURRENT READY AGE
replicaset.apps/application-nginx-loadbalancer-5d8c58775 1 1 1 27m
replicaset.apps/application-test-deployment-65bf678959 1 1 1 27m
replicaset.apps/mysql-deployment-instance-6dff9dcb6b 1 1 1 27m
replicaset.apps/nginx-ingress-controller-6456bbf68 1 1 1 6d1h
replicaset.apps/nginx-ingress-default-backend-674d599c48 1 1 1 6d1h
replicaset.apps/wordpress-deployment-79849f7497 1 1 1 27m
# nginx deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: application-nginx-loadbalancer
spec:
replicas: 1
selector:
matchLabels:
component: frontend
template:
metadata:
labels:
component: frontend
spec:
containers:
- name: nginx
image: rvraj/nginx
ports:
- containerPort: 80
- containerPort: 81
# nginx service
apiVersion: v1
kind: Service
metadata:
name: application-webserver-service
spec:
type: ClusterIP
selector:
component: frontend
ports:
- name: laravel
targetPort: 80
port: 80
- name: wordpress
targetPort: 81
port: 81
# wordpress deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-deployment
spec:
replicas: 1
selector:
matchLabels:
component: wordpress
template:
metadata:
labels:
component: wordpress
spec:
containers:
- name: wordpress
image: wordpress:php7.4-fpm-alpine
ports:
- containerPort: 9000
volumeMounts:
- name: wordpress-storage
mountPath: /var/www/html
volumes:
- name: wordpress-storage
persistentVolumeClaim:
claimName: wordpress-pvc
# wordpress service
apiVersion: v1
kind: Service
metadata:
name: wordpress-service
spec:
type: ClusterIP
selector:
component: wordpress
ports:
- port: 9000
targetPort: 9000
#wordpress pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wordpress-pvc
spec:
storageClassName: ""
accessModes:
- ReadWriteMany
resources:
requests:
storage: 500Mi
# wordpress pv
apiVersion: v1
kind: PersistentVolume
metadata:
name: wordpress-pv-config
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
nfs:
server: 10.148.0.2
path: "/k8s_nfs_disk/wordpress"