Kubernetes Ingress:为什么相同的配置但不同的主机会得到不同的结果?
Kubernetes Ingress: Why I get different results for same configuration, but different hosts?
我已经在裸机上安装了 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
谁能看出是什么导致了几乎相似配置的 strange/different 行为?这是 link 差异:https://www.diffchecker.com/9AlnFQGz
正如@Mariyo 在评论中提到的,问题似乎出在 Cloudflare SSL configuration; in the scenario where your web site does not hold any SSL certificate and you consider using secure connection only with web users and Cloudflare but not with web serve. Then, you might choose Flexible SSL 模式而不是 Full SSL Strict 模式。已经为任何进一步的贡献者研究提供了答案。
我已经在裸机上安装了 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
谁能看出是什么导致了几乎相似配置的 strange/different 行为?这是 link 差异:https://www.diffchecker.com/9AlnFQGz
正如@Mariyo 在评论中提到的,问题似乎出在 Cloudflare SSL configuration; in the scenario where your web site does not hold any SSL certificate and you consider using secure connection only with web users and Cloudflare but not with web serve. Then, you might choose Flexible SSL 模式而不是 Full SSL Strict 模式。已经为任何进一步的贡献者研究提供了答案。