All files referenced are included below. I am trying to create a NGINX proxy to serve my back-end and front-end with the same domain.
Nginx runs successfully, I can tell because I get a 404 error from nginx when I hit the root url given by kubectl get ingress
.
When I hit the url/hello
endpoint, however, I get a 503 Service Temporarily Unavailable
error from Nginx.
Has anyone encountered this error?
Here is the yaml file for my kubectl create -f
command:
kind: Service
apiVersion: v1
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
annotations:
# by default the type is elb (classic load balancer).
service.beta.kubernetes.io/aws-load-balancer-type: nlb
spec:
# this setting is to make sure the source IP address is preserved.
externalTrafficPolicy: Local
type: LoadBalancer
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
ports:
- name: http
port: 80
targetPort: http
# - name: https
# port: 443
# targetPort: https
---
kind: Ingress
apiVersion: networking.k8s.io/v1beta1
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /hello
backend:
serviceName: go-hello
servicePort: 8080
---
kind: Pod
apiVersion: v1
metadata:
name: go-hello
labels:
app: go-hello
spec:
containers:
- name: go-hello
image: docker.io/chsclarke11/test-go
---
kind: Service
apiVersion: v1
metadata:
name: go-hello-service
spec:
selector:
app: go-hello
ports:
- port: 8080 # Default port for image
here is the Dockerfile for the go-hello app:
FROM golang:1.12-alpine
RUN apk add --no-cache git
# Set the Current Working Directory inside the container
WORKDIR /app
RUN go mod download
COPY . .
# Build the Go app
RUN go build -o main
# This container exposes port 8080 to the outside world
EXPOSE 8080
# Run the binary program produced by `go install`
CMD ["./main"]
Here is the go-hello mock application:
package main
import (
"fmt"
"net/http"
)
func main() {
fmt.Printf("starting server at http://localhost:8080")
http.HandleFunc("/", HelloServer)
http.ListenAndServe(":8080", nil)
}
func HelloServer(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}
In Ingress definition you have specified wrong backend service name: go-hello
which is not compatible with service name you created for backend - go-hello-service
.
Also for the future you can get a 503
error from nginx when basic-auth
is enable in the Ingress and the annotation nginx.ingress.kubernetes.io/auth-secret
is referencing a non-existing secret.
You can also add the missing secret or removing all basic-auth
annotations from the Ingress can resolve this situation.