我已经在裸机上安装了 Kubernetes,并弄清楚了如何使用 Ingress 并将主机路由到我的服务。
但是当我对不同的主机使用相同的配置时,我得到default backend - 404
.
工作配置:
apiVersion: v1
kind: Namespace
metadata:
name: k8s-mariyo-host-1-sk-node-hello-world
---
apiVersion: v1
kind: Service
metadata:
namespace: k8s-mariyo-host-1-sk-node-hello-world
name: node-hello-world
labels:
app: node-hello-world
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: node-hello-world
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
namespace: k8s-mariyo-host-1-sk-node-hello-world
name: node-hello-world
spec:
selector:
matchLabels:
app: node-hello-world
strategy:
type: Recreate
template:
metadata:
namespace: k8s-mariyo-host-1-sk-node-hello-world
labels:
app: node-hello-world
spec:
containers:
- image: 10.100.100.1:5000/local-node-hello-world:1.5
name: hello-world
ports:
- containerPort: 8080
name: hello-world
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
namespace: k8s-mariyo-host-1-sk-node-hello-world
name: node-hello-world
spec:
rules:
- host: "node-hello-world.host-1.sk"
http:
paths:
- path: /
backend:
serviceName: node-hello-world
servicePort: 80
默认后端 - 404 配置:
apiVersion: v1
kind: Namespace
metadata:
name: k8s-mariyo-host-2-sk-k8s
---
apiVersion: v1
kind: Service
metadata:
namespace: k8s-mariyo-host-2-sk-k8s
name: k8s
labels:
app: k8s
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: k8s
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
namespace: k8s-mariyo-host-2-sk-k8s
name: k8s
spec:
selector:
matchLabels:
app: k8s
strategy:
type: Recreate
template:
metadata:
namespace: k8s-mariyo-host-2-sk-k8s
labels:
app: k8s
spec:
containers:
- image: 10.100.100.1:5000/local-node-hello-world:1.5
name: k8s-hello
ports:
- containerPort: 8080
name: k8s-hello
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
namespace: k8s-mariyo-host-2-sk-k8s
name: k8s
spec:
rules:
- host: "k8s.host-2.sk"
http:
paths:
- path: /
backend:
serviceName: k8s
servicePort: 80
任何人都可以看到什么会导致几乎类似配置的奇怪/不同行为?这是 diff 的链接:https ://www.diffchecker.com/9AlnFQGz