Nginx Ingress 在 microk8s 上提供 404 并提供工作服务
在 Ubuntu 20.04.4 LTS 上运行 microk8s v1.23.3。我已经设置了一个最小的 pod+service:
kubectl create deployment whoami --image=containous/whoami --namespace=default
这按预期工作,curl 10.1.76.4:80
给出了 whoami
的正确回复。 我配置了一个服务,请参阅 service-whoami.yaml
的内容:
apiVersion: v1
kind: Service
metadata:
name: whoami
namespace: default
spec:
selector:
app: whoami
ports:
- protocol: TCP
port: 80
targetPort: 80
这也按预期工作,可以通过 curl 10.152.183.220:80
上的 clusterIP 访问 pod 。 现在我想使用 ingress-whoami.yaml
公开服务:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: whoami-ingress
namespace: default
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
defaultBackend:
service:
name: whoami
port:
number: 80
rules:
- http:
paths:
- path: /whoami
pathType: Prefix
backend:
service:
name: whoami
port:
number: 80
启用了 ingress 插件。
microk8s is running
high-availability: no
datastore master nodes: 127.0.0.1:19001
datastore standby nodes: none
addons:
enabled:
ha-cluster # Configure high availability on the current node
ingress # Ingress controller for external access
入口似乎指向正确的 Pod 和端口。 kubectl描述入口
给出
Name: whoami-ingress
Labels: <none>
Namespace: default
Address:
Default backend: whoami:80 (10.1.76.12:80)
Rules:
Host Path Backends
---- ---- --------
*
/whoami whoami:80 (10.1.76.12:80)
Annotations: <none>
Events: <none>
尝试使用curl 127.0.0.1/whoami
从外部到达pod会给出404
:
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
我哪里出错了?这个设置在几周前就起作用了。
Running microk8s v1.23.3 on Ubuntu 20.04.4 LTS. I have set up a minimal pod+service:
kubectl create deployment whoami --image=containous/whoami --namespace=default
This works as expected, curl 10.1.76.4:80
gives the proper reply from whoami
.
I have a service configured, see content of service-whoami.yaml
:
apiVersion: v1
kind: Service
metadata:
name: whoami
namespace: default
spec:
selector:
app: whoami
ports:
- protocol: TCP
port: 80
targetPort: 80
This also works as expected, the pod can be reached through the clusterIP on curl 10.152.183.220:80
.
Now I want to expose the service using the ingress-whoami.yaml
:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: whoami-ingress
namespace: default
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
defaultBackend:
service:
name: whoami
port:
number: 80
rules:
- http:
paths:
- path: /whoami
pathType: Prefix
backend:
service:
name: whoami
port:
number: 80
ingress addon is enabled.
microk8s is running
high-availability: no
datastore master nodes: 127.0.0.1:19001
datastore standby nodes: none
addons:
enabled:
ha-cluster # Configure high availability on the current node
ingress # Ingress controller for external access
ingress seems to point to the correct pod and port. kubectl describe ingress
gives
Name: whoami-ingress
Labels: <none>
Namespace: default
Address:
Default backend: whoami:80 (10.1.76.12:80)
Rules:
Host Path Backends
---- ---- --------
*
/whoami whoami:80 (10.1.76.12:80)
Annotations: <none>
Events: <none>
Trying to reach the pod from outside with curl 127.0.0.1/whoami
gives a 404
:
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
Where did I go wrong? This setup worked a few weeks ago.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,想通了。
我忘记在注释块中指定
ingress.class
。我更新了
ingress-whoami.yaml
:现在一切正常。
Ok, figured it out.
I had forgotten to specify the
ingress.class
in the annotations-block.I updated
ingress-whoami.yaml
:Now everything is working.