amazon-web-services - Amazon EKS上带有NGINX Ingress Controller 的网络负载均衡器始终返回503错误

标签 amazon-web-services docker nginx kubernetes http-status-code-404

下面引用了所有文件。我正在尝试创建一个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/

相关文章:

nginx - Flask Restplus Swagger 不在 Nginx 后面加载

reactjs - Kubernetes中的后端/前端服务之间没有通信

json - aws lambda node js返回对象实例的转义JSON

reactjs - 将用户添加到 Cognito 后刷新 Cognito 访问 token

java - 使用 java 在 SNS 主题上出现 InvalidParameterException

php - 使用 bookworm 在 Docker 中为 PHP8.1 添加 Memcached 支持时出现问题

postgresql - AWS RDS 上的高 CPU 使用率 - Postgres

docker - 在 dockerising nest.js 应用程序上出错

docker 推送错误 "denied: requested access to the resource is denied"

Nginx代理: connect() to ip:80 failed (99: Cannot assign requested address)