Kubernetes入口返回一个502坏网关



因此,我正在尝试部署一个个人网站应用程序,并将其公开到本地域(目前(,但我总是从我的nginx入口控制器收到一个502坏网关。因此,对于这样的任务,我构建了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入口控制器的一些日志:

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入口控制器只需将其添加为插件即可进行配置。我怀疑问题出在我的入口配置上,因为我已经通过端口转发了部署的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清单中的targetPortDeployment清单中的containerPort需要与容器内的服务器正在侦听的端口匹配

由于nginx默认在端口80上侦听,因此应该将其更改为端口80。否则,容器中的服务器应该更改为在不同的端口上侦听。对于nginx,这可以通过nginx.conf文件或设置NGINX_PORT环境变量来完成。看见https://hub.docker.com/_/nginx详细信息。

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

相关内容

  • 没有找到相关文章

最新更新