gpt4 book ai didi

Kubernetes 入口返回 502 错误网关

转载 作者:行者123 更新时间:2023-12-04 15:09:03 25 4
gpt4 key购买 nike

所以,我正在尝试部署个人网站应用程序并将其公开到本地域(目前),但我总是从我的 nginx-ingress-controller 收到 502 Bad Gateway。因此,对于这样的任务,我构建了 3 个文件:deployment.yamlservice.yamlingress.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
name: website-deployment
labels:
app: website
spec:
replicas: 1
selector:
matchLabels:
app: website
template:
metadata:
labels:
app: website
spec:
containers:
- name: website
image: jotinha2014/private
ports:
- containerPort: 55004
    apiVersion: v1
kind: Service
metadata:
name: website-service
spec:
selector:
app: website
ports:
- protocol: TCP
port: 80
targetPort: 55004
type: ClusterIP
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: website-ingress
namespace: default
annotations:
nginx.ingress.kubernetes.io/service-upstream: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: rabanadas.eu
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: website-service
port:
number: 80

这是我的 nginx-ingress-controller 的一些日志:

2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: "GET / HTTP/1.1", upstream: "http://10.106.8.10:80/", host: "rabanadas.eu"
2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: "GET / HTTP/1.1", upstream: "http://10.106.8.10:80/", host: "rabanadas.eu"
2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: "GET / HTTP/1.1", upstream: "http://10.106.8.10:80/", host: "rabanadas.eu"
192.168.64.1 - - [03/Jan/2021:01:13:31 +0000] "GET / HTTP/1.1" 502 552 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" 474 0.000 [default-website-service-80] [] 10.106.8.10:80, 10.106.8.10:80, 10.106.8.10:80 0, 0, 0 0.000, 0.000, 0.000 502, 502, 502 dff7944bbbc17be35584fee465d047d2
W0103 01:15:52.298006 8 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress

现在我正在使用 minikube,因此,我的 nginx-ingress-controller 只需将其添加为 addon 即可配置。我怀疑问题出在我的入口配置上,因为我已经对部署的 pod 进行了端口转发,并且该网站显示在正确的端口上。

根据要求,这是我的网站 pod 详细信息:

Name:         website-deployment-69f57fc45-l4th9
Namespace: default
Priority: 0
Node: minikube/192.168.64.5
Start Time: Sun, 03 Jan 2021 00:53:16 +0000
Labels: app=website
pod-template-hash=69f57fc45
Annotations: <none>
Status: Running
IP: 172.17.0.2
IPs:
IP: 172.17.0.2
Controlled By: ReplicaSet/website-deployment-69f57fc45
Containers:
website:
Container ID: docker://eae48617da80f3ac4832695535432581746d925fc497066a5fd8a707b3020a88
Image: jotinha2014/private
Image ID: docker-pullable://jotinha2014/private@sha256:0a9573429315745eae0a33339021c82db2e92e0ba35ca652aa20482af31f1219
Port: 55004/TCP
Host Port: 0/TCP
State: Running
Started: Sun, 03 Jan 2021 00:53:18 +0000
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-j8pzx (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-j8pzx:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-j8pzx
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events: <none>

在此先感谢您的帮助。

最佳答案

根据评论; Service list 中的targetPortDeployment list 中的containerPort需要匹配服务端的端口容器内正在监听。

由于 nginx 默认监听端口 80,因此应将这些更改为端口 80。否则,应将容器中的服务器更改为监听不同的端口。对于 nginx,这可以通过 nginx.conf 文件或通过设置 NGINX_PORT 环境变量来完成。参见 https://hub.docker.com/_/nginx了解详情。

通常,您会为每个 pod 运行一个容器,因此很少需要将端口更改为 80 以外的端口。

关于Kubernetes 入口返回 502 错误网关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65545833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com