【发布时间】:2021-07-18 15:40:12
【问题描述】:
我正在尝试使用 Kubernetes Ingress Nginx 控制器并在 AWS EKS 中运行一个简单的 nginx 服务器。
浏览器 (https) --> Route 53 (DNS) --> CLB --> nginx Ingress (Terminate TLS) --> 服务 --> POD
但我在浏览器中收到 404 错误(使用的网址:https://example.com/my-nginx):
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.19.10</center>
</body>
</html>
在入口日志(kubectl logs -n nginx-ingress nginx-ingress-nginx-controller-6db6f85bc4-mfpwx)中,我可以看到如下:
192.168.134.181 - - [24/Apr/2021:19:02:01 +0000] "GET /my-nginx HTTP/2.0" 404 154 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64 ; rv:88.0) Gecko/20100101 Firefox/88.0" 219 0.002 [eshop-dev-my-nginx-9443] [] 192.168.168.105:80 154 0.000 404 42fbe692a032bb40bf193954526369cd
这是我的部署 yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
namespace: eshop-dev
spec:
selector:
matchLabels:
run: my-nginx
replicas: 2
template:
metadata:
labels:
run: my-nginx
spec:
containers:
- name: my-nginx
image: nginx
ports:
- containerPort: 80
服务 yaml:
apiVersion: v1
kind: Service
metadata:
namespace: eshop-dev
name: my-nginx
spec:
selector:
run: my-nginx
ports:
- name: server
port: 9443
targetPort: 80
protocol: TCP
和入口 yaml:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-ingress
namespace: eshop-dev
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: example.com
http:
paths:
- path: /my-nginx
pathType: ImplementationSpecific
backend:
service:
name: my-nginx
port:
number: 9443
tls:
- hosts:
- example.com
secretName: externaluicerts
我已验证服务在与端口转发一起使用时返回所需的输出:
kubectl -n eshop-dev port-forward service/my-nginx 9443:9443
我不确定入口是否配置错误,或者是否是另一个问题。提前感谢您的帮助!
这里是 kubectl get ingress -n eshop-dev test-ingress -o yaml 的输出
kubectl get ingress -n eshop-dev test-ingress -o yaml
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"networking.k8s.io/v1","kind":"Ingress","metadata":{"annotations":{"kubernetes.io/ingress.class":"nginx"},"name":"test-ingress","namespace":"eshop-dev"},"spec":{"rules":[{"host":"example.com","http":{"paths":[{"backend":{"service":{"name":"my-nginx","port":{"number":9443}}},"path":"/my-nginx","pathType":"ImplementationSpecific"}]}}],"tls":[{"hosts":["example.com"],"secretName":"externaluicerts"}]}}
kubernetes.io/ingress.class: nginx
creationTimestamp: "2021-04-24T13:16:21Z"
generation: 13
managedFields:
- apiVersion: networking.k8s.io/v1beta1
fieldsType: FieldsV1
fieldsV1:
f:status:
f:loadBalancer:
f:ingress: {}
manager: nginx-ingress-controller
operation: Update
time: "2021-04-24T13:16:40Z"
- apiVersion: extensions/v1beta1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations: {}
manager: kubectl-client-side-apply
operation: Update
time: "2021-04-24T13:18:36Z"
- apiVersion: networking.k8s.io/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
f:kubectl.kubernetes.io/last-applied-configuration: {}
f:kubernetes.io/ingress.class: {}
f:spec:
f:rules: {}
f:tls: {}
manager: kubectl-client-side-apply
operation: Update
time: "2021-04-24T16:33:47Z"
name: test-ingress
namespace: eshop-dev
resourceVersion: "7555944"
selfLink: /apis/extensions/v1beta1/namespaces/eshop-dev/ingresses/test-ingress
uid: a7694655-20c6-48c7-8adc-cf3a53cf2ffe
spec:
rules:
- host: example.com
http:
paths:
- backend:
serviceName: my-nginx
servicePort: 9443
path: /my-nginx
pathType: ImplementationSpecific
tls:
- hosts:
- example.com
secretName: externaluicerts
status:
loadBalancer:
ingress:
- hostname: xxxxxxxxxxxxxxxxdc75878b2-433872486.eu-west-1.elb.amazonaws.com
【问题讨论】:
-
欢迎来到 StackOverflow!入口 port.number 似乎有太多缩进,不确定这是否是问题。能否请您发布 k get ingress -n eshop-dev test-ingress -oyaml 的结果?
-
谢谢,我已经编辑了原始帖子以包含 k get ingress -n eshop-dev test-ingress -o yaml 的输出。输出太长,不允许我发表评论。
-
谢谢!我添加了一个我认为可能是问题和解决方案的答案。让我知道它是否有效。
标签: kubernetes https kubernetes-ingress amazon-eks nginx-ingress