繁体   English   中英

Amazon EKS 上带有 NGINX 入口控制器的网络负载均衡器始终返回 503 错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM