kubernetes ingress always return 503

4/26/2020

I deployed kubernetes on my computer and config pod, service, ingress. I curl the domain that I configured but get 503 error. What's the reason?
Operating System: Mac OSX 10.15.3
Docker version: 19.03.8
the pod:

apiVersion: v1
kind: Pod
metadata:
  name: opengateway
  namespace: openplatform
spec:
  containers:
    - name: opengateway
      image: "karldoenitz/opengateway:1.0"
      ports:
        - containerPort: 8000
          hostPort: 8000
      env:
        - name: etcdiport
          valueFrom:
            configMapKeyRef:
              name: openplatform
              key: etcd-iport
      imagePullPolicy: IfNotPresent

the service

apiVersion: v1
kind: Service
metadata:
  name: webgateway
  namespace: openplatform
spec:
  ports:
    - port: 8000
      targetPort: 8000
  selector:
    app: opengateway

the ingress

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: openplatform-web-gateway
  namespace: openplatform
spec:
  rules:
    - host: open.platform.com
      http:
        paths:
          - path: /
            backend:
              serviceName: webgateway
              servicePort: 8000

describe svc webgateway -n openplatform

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

the log of ingress-controller :

192.168.65.3 - - [26/Apr/2020:08:58:37 +0000] "GET /favicon.ico HTTP/1.1" 503 599 "http://open.platform.com/ping" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36" 388 0.000 [openplatform-openplatform-web-gateway-30001] [] - - - - 086d5a61011485f8fa69dca25afd93ae

all the pod, service, ingress is running.I run the command curl http://open.platform.com, I got error 503 Service Temporarily Unavailable. What's the matter?

-- Karl Doenitz
kubernetes
kubernetes-ingress

1 Answer

4/26/2020

So the problem here is that the service has a label selector which selects pods with label app: opengateway but the pods don't have this label. Because of this the Endpoints in the service is empty and does not have the POD IPs. Adding label app: opengateway into the pod should solve it.

apiVersion: v1
kind: Pod
metadata:
  name: opengateway
  namespace: openplatform
  labels:
    app: opengateway
spec:
  containers:
    - name: opengateway
      image: "karldoenitz/opengateway:1.0"
      ports:
        - containerPort: 8000
          hostPort: 8000
      env:
        - name: etcdiport
          valueFrom:
            configMapKeyRef:
              name: openplatform
              key: etcd-iport
      imagePullPolicy: IfNotPresent
-- Arghya Sadhu
Source: StackOverflow