skip to Main Content

I am trying to deploy WordPress on GKE, everything is ok except the ingress, the ingress is not able to connect to backend service, showing " SOME BACKEND SERVICES ARE IN UNHEALTHY STATE"
I would be grateful if someone help me.

WordPress deployment yaml file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress-deployment
  labels:
    app: wordpress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      containers:
      - name: wordpress
        image: wordpress
        ports:
        - containerPort: 80
        volumeMounts:
          - name: wordpress-persistent-storage
            mountPath: /var/www/html
        env:
        - name: WORDPRESS_DB_HOST
          value: mysql-service
        - name: WORDPRESS_DB_USER
          value: wpuser
        - name: WORDPRESS_DB_PASSWORD
          value: pass@123
        - name: WORDPRESS_DB_NAME
          value: wpdb
        - name: WORDPRESS_DEBUG
          value: "1"
      volumes:
        - name: wordpress-persistent-storage
          persistentVolumeClaim:
            claimName: wordpress-volumeclaim

Service yaml file

apiVersion: v1
kind: Service
metadata:
  name: wordpress-service
spec:
  type: NodePort
  selector:
    app: wordpress
  ports:
  - name: portname
    nodePort: 30100
    port: 80
    targetPort: 80
    

Ingress yaml file

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: wordpress-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: my-address
    networking.gke.io/managed-certificates: managed-cert
    kubernetes.io/ingress.class: "gce"
spec:
  rules:
    - host: example.com 
    - http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: wordpress-service
              port:
                number: 80
                

Ingress GCP Consol

Ingress GCP Consol

GCP logs

2

Answers


  1. In your spec

    spec:
      rules:
        - host: example.com 
        - http:
            paths:
            - path: /
              pathType: Prefix
              backend:
                service:
                  name: wordpress-service
                  port:
                    number: 80
    

    you accidentally have two different backends: one for "example.com" and one based on the path "/" for anything else. Since you are not specifying a backend for the "example.com", Ingress uses the default backend, which will never return healthy.

    My guess is that you don’t actually want "example.com", so deleting it from the spec should solve your issue:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: wordpress-ingress
      annotations:
        kubernetes.io/ingress.global-static-ip-name: my-address
        networking.gke.io/managed-certificates: managed-cert
        kubernetes.io/ingress.class: "gce"
    spec:
      rules:
        - http:
            paths:
            - path: /
              pathType: Prefix
              backend:
                service:
                  name: wordpress-service
                  port:
                    number: 80
    
    Login or Signup to reply.
  2. You can try to go to https://console.cloud.google.com/compute/healthChecks/ and then modify the health check for the wordpress backend. For example changing it from / to /wp-admin/images/wordpress-logo.svg solved the issue in my case. This is described in this post https://serverfault.com/questions/826719/how-to-create-a-url-in-a-wordpress-that-will-return-code-200.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search