How to fix "503 Service Temporarily Unavailable"

10/25/2019

FYI:

  1. I run Kubernetes on docker desktop for mac
  2. The website based on Nginx image

I run 2 simple website deployments on Kubetesetes and use the NodePort service. Then I want to make routing to the website using ingress. When I open the browser and access the website, I get an error 503 like images below. So, how do I fix this error?

### Service
apiVersion: v1
kind: Service
metadata:
  name: app-svc
  labels:
    app: app1
spec:
  type: NodePort
  ports:
  - port: 80
  selector:
    app: app1
---
apiVersion: v1
kind: Service
metadata:
  name: app2-svc
  labels:
    app: app2
spec:
  type: NodePort
  ports:
  - port: 80
  selector:
    app: app2

### Ingress-Rules
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: app-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /app1
        backend:
          serviceName: app-svc
          servicePort: 30092
      - path: /app2
        backend:
          serviceName: app2-svc
          servicePort: 30936

enter image description here

-- Rexy Sihombing
docker-desktop
kubernetes
kubernetes-ingress
nginx-ingress

2 Answers

10/25/2019

I advise you to use service type ClusterIP Take look on this useful article: services-kubernetes.

If you use Ingress you have to know that Ingress isn’t a type of Service, but rather an object that acts as a reverse proxy and single entry-point to your cluster that routes the request to different services. The most basic Ingress is the NGINX Ingress Controller, where the NGINX takes on the role of reverse proxy, while also functioning as SSL. On below drawing you can see workflow between specific components of environment objects.

Ingress is exposed to the outside of the cluster via ClusterIP and Kubernetes proxy, NodePort, or LoadBalancer, and routes incoming traffic according to the configured rules.

Example of service definition:

---
apiVersion: v1
kind: Service
metadata:
  name: app-svc
  labels:
    app: app1
spec:
  type: ClusterIP
  ports:
  - port: 80
  selector:
    app: app1
---
apiVersion: v1
kind: Service
metadata:
  name: app2-svc
  labels:
    app: app2
spec:
  type: ClusterIP
  ports:
  - port: 80
  selector:
    app: app2

Let me know if it helps.

-- MaggieO
Source: StackOverflow

4/28/2020

Yes, i end up with same error. once i changed the service type to "ClusterIP", it worked fine for me.

-- Srinivas Charan Mamidi
Source: StackOverflow