kubernetes traefik ingress 503 bad gateway error

10/30/2020

As I want to learn to deploy software with kubernetes, I installed a single node k3s cluster (ip: 192.168.178.10) with curl -sfL https://get.k3s.io | sh -. Now I followed this tutorial to get two services up and expose them to the outside. But when i try curl 192.168.178.10/apple the responce is Bad Gateway I think it has something to do with the k3s traefik ingeress, but i wasn't able to locate the problem.

services

kind: Pod
apiVersion: v1
metadata:
  name: banana-app
  labels:
    app: banana
spec:
  containers:
    - name: banana-app
      image: hashicorp/http-echo
      args:
        - "-text=banana"

---

kind: Service
apiVersion: v1
metadata:
  name: banana-service
spec:
  selector:
    app: banana
  ports:
    - port: 5678 # Default port for image
kind: Pod
apiVersion: v1
metadata:
  name: apple-app
  labels:
    app: apple
spec:
  containers:
    - name: apple-app
      image: hashicorp/http-echo
      args:
        - "-text=apple"

---

kind: Service
apiVersion: v1
metadata:
  name: apple-service
spec:
  selector:
    app: apple
  ports:
    - port: 5678 # Default port for image

ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
        - path: /apple
          backend:
            serviceName: apple-service
            servicePort: 5678
        - path: /banana
          backend:
            serviceName: banana-service
            servicePort: 5678

Edit: kubectl describe ingress example-ingress shows th following rules:

Rules:
  Host  Path  Backends
  ----  ----  --------
  *     
        /apple    apple-service:5678 (10.42.0.68:5678)
        /banana   banana-service:5678 (10.42.0.67:5678)

while thoise are the services for apple and banana:

NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
apple-service    ClusterIP   10.43.61.250   <none>        5678/TCP   101m
banana-service   ClusterIP   10.43.67.205   <none>        5678/TCP   100m

The ip's don't match what seems like a problem for me.


output of kubectl describe svc:

 Name:              kubernetes
Namespace:         default
Labels:            component=apiserver
                   provider=kubernetes
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
IP:                10.43.0.1
Port:              https  443/TCP
TargetPort:        6443/TCP
Endpoints:         192.168.178.10:6443
Session Affinity:  None
Events:            <none>


Name:              banana-service
Namespace:         default
Labels:            <none>
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"banana-service","namespace":"default"},"spec":{"ports":[{"port":5...
Selector:          app=banana
Type:              ClusterIP
IP:                10.43.124.19
Port:              <unset>  5678/TCP
TargetPort:        5678/TCP
Endpoints:         10.42.0.76:5678
Session Affinity:  None
Events:            <none>


Name:              apple-service
Namespace:         default
Labels:            <none>
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"apple-service","namespace":"default"},"spec":{"ports":[{"port":56...
Selector:          app=apple
Type:              ClusterIP
IP:                10.43.9.134
Port:              <unset>  5678/TCP
TargetPort:        5678/TCP
Endpoints:         10.42.0.77:5678
Session Affinity:  None
Events:            <none>
-- 8bit
k3s
kubernetes
traefik-ingress

0 Answers