[英]Network Load Balancer with the NGINX Ingress Controller on Amazon EKS always returns a 503 error
所有引用的文件都包含在下面。 我正在嘗試創建一個 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 中啟用basic-auth
並且注釋nginx.ingress.kubernetes.io/auth-secret
引用一個不存在的秘密時,您可能會從 nginx 收到503
錯誤。
您還可以添加缺少的密鑰或從 Ingress 中刪除所有basic-auth
注釋可以解決這種情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.