下面引用了所有文件。我正在尝试创建一个NGINX代理,以在同一域中为我的后端和前端提供服务。
我知道Nginx运行成功,因为当我打到kubectl get ingress
给定的根URL时,我从Nginx收到404错误。
但是,当我到达url/hello
端点时,我从Nginx收到了503 Service Temporarily Unavailable
错误。
有没有人遇到这个错误?
这是我的kubectl create -f
命令的yaml文件:
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
这是go-hello应用程序的Dockerfile:
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"]
这是go-hello模拟应用程序:
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:])
}
最佳答案
在Ingress定义中,您指定了错误的后端服务名称:go-hello
,它与您为后端创建的服务名称-g o-hello-service
不兼容。
另外,将来在Ingress中启用503
并且注释basic-auth
引用了不存在的 secret 时,您可能会从nginx中收到nginx.ingress.kubernetes.io/auth-secret
错误。
您还可以添加丢失的 secret ,或者从Ingress中删除所有basic-auth
批注可以解决这种情况。
关于amazon-web-services - Amazon EKS上带有NGINX Ingress Controller 的网络负载均衡器始终返回503错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60941939/