Kubernetes Nginx Ingress phpmyadmin 502 error

11/7/2020

I am trying to solve quite an annoying problem I encounter when using Kubernetes. When I am trying to reach PHPMyAdmin on my server, it returns an Nginx 502 Bad Gateway error.

My structure in my cluster is as follows. I use an Nginx ingress LoadBalancer on DigitalOcean to get traffic into my cluster. It then passes my ingress (in the first code block), which splits the traffic across the subdomains. When traffic goes to the phpmyadmin subdomain, the request is passed to the 'phpmyadmin-service' with service port 8085.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: "app1.example.com"
    http:
      paths:
      - path: /
        backend:
          serviceName: app1-service
          servicePort: 80 
  - host: "phpmyadmin.example.com"
    http:
      paths:
      - path: /
        backend:
          serviceName: phpmyadmin-service
          servicePort: 8085

Then, the service receives the request, and passes it to the 'phpmyadmin-deployment' deployment. This is a deployment that runs the phpmyadmin/phpmyadmin:fpm docker image.

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  name: phpmyadmin-deployment
  labels:
    app: phpmyadmin
spec:
  selector:
    matchLabels:
      app: phpmyadmin
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: phpmyadmin
    spec:
      containers:
        - name: phpmyadmin
          image: phpmyadmin/phpmyadmin:fpm
          ports:
          - containerPort: 8087
          env:
          - name: PMA_ABSOLUTE_URI
            value: 'phpmyadmin.example.com'
          - name: PMA_HOST
            value: mysql
          - name: PMA_PORT
            value: "3306"
          - name: MYSQL_ROOT_PASSWORD
            valueFrom:
                secretKeyRef:
                  name: mysql-secrets
                  key: rootpw
---
apiVersion: v1
kind: Service
metadata:
  name: phpmyadmin-service
spec:
  type: ClusterIP
  selector:
    app: phpmyadmin
  ports:
  - port: 8085
    targetPort: 8087

So something is giving me the 502 Bad Gateway error, and I don't know what it is. Thanks in advance for replying!

-- Jurjen
kubernetes
kubernetes-ingress
nginx-ingress
phpmyadmin

0 Answers