入口-连接被拒绝



我知道他们有很多类似的问题,但是在我读了所有的之后,我无法弄清楚…:/

首先我用的不是minikube,我用的是kubernetes docker desktop

我有简单的express.js服务器,如:

app.get('/test', async (_, res) => {
console.log("Sth happened")
res.json({ status: 200 });
});

我正在尝试部署它并使用入口将其暴露给我的本地主机。

我所做的:在etc/hosts中我添加了:

127.0.0.1 123test.mydomain.com

入口如下:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: mytestservice
namespace: mytestservice
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: 123test.mydomain.com
http:
paths:
- pathType: ImplementationSpecific
path: /
backend:
service:
name: mytestservice
port:
number: 80

服务:

apiVersion: v1
kind: Service
metadata:
name: mytestservice
spec:
ports:
- name: http
port: 80
targetPort: 3000
selector:
name: mytestservice

部署:

apiVersion: apps/v1
kind: Deployment
metadata:
name: mytestservice
spec:
replicas: 1
selector:
matchLabels:
name: mytestservice
template:
metadata:
labels:
name: mytestservice
spec:
containers:
- name: mytestservice
image: myimagename
imagePullPolicy: IfNotPresent 
ports:
- containerPort: 3000
env:
...my envs, doesnt matter

当我部署它时,pod已经启动并运行,因为我能够看到启动日志入口描述

kubectl get ingress mytestservice
NAME        CLASS    HOSTS                     ADDRESS   PORTS     AGE
mytestservice   <none>   123test.mydomain.com             80, 443   53s
kubectl describe ingress mytestservice
Name:             mytestservice
Namespace:        mytestservice
Address:
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host                     Path  Backends
----                     ----  --------
123test.mydomain.com
/   mytestservice:80 (10.1.0.16:3000)
Annotations:               kubernetes.io/ingress.class: nginx
meta.helm.sh/release-name: mytestservice
meta.helm.sh/release-namespace: mytestservice
Events:                    <none>

当我卷起它时,我收到:

curl 123test.mydomain.com/test
curl: (7) Failed to connect to 123test.mydomain.com port 80: Connection refused 

问题是DNS。在你的本地/etc/hosts中,你指向的是localhost,而不是Kubernetes主机的IP。

您是否在同一个名称空间中创建了所有资源?我看到你的入口被定义为:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: mytestservice
namespace: mytestservice

,所以它将在mytestservice命名空间中创建。而您的部署和服务在元数据中没有namespace: mytestservice。因此,它们将被创建在default命名空间中。

检查是否所有的资源都在同一个命名空间中:

kubectl get deployments --namespace mytestservice
kubectl get service --namespace mytestservice
kubectl get ingress --namespace mytestservice

在入口的描述中提示错误:

Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)

相关内容

  • 没有找到相关文章

最新更新