Kubernetes Traefik Ingress getting a bad gateway error

8/2/2019

I've set up the following Ingress and deployment for Traefik on Kubernetes. I keep getting a bad gateway error on the actual domain name.

For some reason the service isn't working or I have got the connections wrong or something is amiss with the selectors etc.

apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    app: wordpress
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
    - name: http
      port: 80
      targetPort: 80
      protocol: TCP
  selector:
    app: wordpress

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: web-ingress
  annotations:
    kubernetes.io/ingress.class: traefik
    # traefik.ingress.kubernetes.io/frontend-entry-points: http,https
spec:
  rules:
  - host: test.example.services
    http:
      paths:
      - path: /
        backend:
          serviceName: web
          servicePort: http




---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
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:4.8-apache
        name: wordpress
        env:
        - name: WORDPRESS_DB_HOST
          value: wordpress-mysql
        - name: WORDPRESS_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 80
          name: wordpress
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html
      volumes:
      - name: wordpress-persistent-storage
        persistentVolumeClaim:
          claimName: wp-pv-claim

My code is below so if there are any corrections to be made, advice is appreciated.

-- Rutnet
kubernetes
traefik
traefik-ingress

1 Answer

8/14/2019

There are few things to consider:

  1. I see that you are missing the namsespace: in your metadata:. Check if that is the case.

  2. Try to create two services. One for wordpress and one for treafik-ingress-lb.

  3. You might have used too many spaces after ports:. Try something like this:

      ports:
      - name: http
        port: 80
        targetPort: 80
        protocol: TCP
  1. Check if your labels are correctly configured. If you need more detials regarding them, try this documentation.

Please let me know if that helped.

-- OhHiMark
Source: StackOverflow