为什么我的裸机kubernetes nginx Ingress控制器返回308? [英] Why does my bare-metal kubernetes nginx Ingress-controller return a 308?
问题描述
我试图创建将Nginx入口控制器添加到我的kubernetes集群中.我当前的群集有3个节点,并且它们之间都具有开放的防火墙规则. (注意:这是出于教育目的的裸机集群)
I am trying to create add the nginx ingress controller to my kubernetes cluster. My current cluster has 3 nodes and they all have open firewall rules in between them. (Note: This is a bare metal cluster for educational purposes)
我已经使用以下配置创建了部署
I have created a deployment with the following config
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-test
labels:
app: nodejs
spec:
replicas: 5
selector:
matchLabels:
app: nodejs
template:
metadata:
labels:
app: nodejs
spec:
containers:
- name: nodejs-container
image: gcr.io/infrastructure/test-nodejs-server
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: test-deployment-service
spec:
selector:
app: nodejs
ports:
- protocol: TCP
port: 80
targetPort: 3000
运行kubectl后,创建-f file.yaml
After running kubectl create -f file.yaml
我看到所有Pod和服务都在运行.在群集中,我可以卷曲该服务ip并从Pod中获得响应.
I see all pods and services running. Within the cluster I can curl that service ip and get a response from the pods.
现在我要创建一个入口.
Now I go to create a ingress.
我首先遵循在 https://github.com/上找到的安装步骤kubernetes/ingress-nginx/tree/master/deploy
我可以看到我的入口控制器正在运行.
I can see my ingress controller running.
NAMESPACE NAME READY STATUS RESTARTS AGE
default my-test-6445d9bb7b-blm7t 1/1 Running 0 3h
default nodejs-test-5657f7bb74-7hwqk 1/1 Running 0 23h
default nodejs-test-5657f7bb74-bh44x 1/1 Running 0 23h
default nodejs-test-5657f7bb74-dw4g4 1/1 Running 0 23h
default nodejs-test-5657f7bb74-k7bf4 1/1 Running 0 23h
default nodejs-test-5657f7bb74-xdthl 1/1 Running 0 23h
ingress-nginx default-http-backend-55c6c69b88-4d5bf 1/1 Running 0 26m
ingress-nginx nginx-ingress-controller-5c6698dfbf-gs9zd 1/1 Running 0 25m
kube-system etcd-yoda.me.com 1/1 Running 1 1d
kube-system kube-apiserver-yoda.me.com 1/1 Running 1 1d
kube-system kube-controller-manager-yoda.me.com 1/1 Running 1 1d
kube-system kube-dns-6f4fd4bdf-62bxg 3/3 Running 3 1d
kube-system kube-flannel-ds-jbmwg 1/1 Running 1 1d
kube-system kube-flannel-ds-r8nfb 1/1 Running 2 1d
kube-system kube-flannel-ds-rczbx 1/1 Running 0 1d
kube-system kube-proxy-brm2g 1/1 Running 0 1d
kube-system kube-proxy-qjgcv 1/1 Running 1 1d
kube-system kube-proxy-sz6rw 1/1 Running 1 1d
kube-system kube-scheduler-yoda.me.com 1/1 Running 1 1d
kube-system kubernetes-dashboard-5bd6f767c7-stscl 1/1 Running 1 23h
kube-system tiller-deploy-59d854595c-tngg6 1/1 Running 0 23h
然后我使用以下文件创建入口
I then create my ingress with the following file
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- http:
paths:
- path: /whoop
backend:
serviceName: test-deployment-service
servicePort: 80
然后我运行kubectl get services --all-namespaces来找到我的入口控制器端口.
Then I run kubectl get services --all-namespaces to find my ingress controller port.
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1d
default my-test ClusterIP 10.110.102.5 <none> 80/TCP 4h
default test-deployment-service ClusterIP 10.104.239.37 <none> 80/TCP 23h
ingress-nginx default-http-backend ClusterIP 10.105.218.87 <none> 80/TCP 29m
ingress-nginx ingress-nginx NodePort 10.110.39.104 <none> 80:30652/TCP,443:31624/TCP 27m
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 1d
kube-system kubernetes-dashboard ClusterIP 10.100.219.110 <none> 443/TCP 23h
kube-system tiller-deploy ClusterIP 10.101.179.202 <none> 44134/TCP 23h
现在我要卷曲服务器:
curl -v myserver:30652/whoop/
结果是:
* Trying myip...
* TCP_NODELAY set
* Connected to myserver (myip) port 30652 (#0)
> GET /whoop/ HTTP/1.1
> Host: myserver:30652
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 308 Permanent Redirect
< Server: nginx/1.13.9
< Date: Fri, 02 Mar 2018 14:38:21 GMT
< Content-Type: text/html
< Content-Length: 187
< Connection: keep-alive
< Location: https://myserver:30652/whoop/
< Strict-Transport-Security: max-age=15724800; includeSubDomains;
<
<html>
<head><title>308 Permanent Redirect</title></head>
<body bgcolor="white">
<center><h1>308 Permanent Redirect</h1></center>
<hr><center>nginx/1.13.9</center>
</body>
</html>
* Connection #0 to host myserver left intact
我希望能从豆荚中得到回应.但是我总是得到308.
I would expect to be getting the response from my pods. However I always get the 308.
如果我卷曲随机路径
卷曲myserver:30652/random
curl myserver:30652/random
我得到的答复是
default backend - 404
如何连接我的入口和入口控制器以使路由正常工作?
How can I hook up my ingress and ingress controller for the routing to work correctly?
推荐答案
此处的关键是命名主机,否则入口规则将应用于默认服务器,默认情况下,该服务器配置为将HTTP重定向到HTTPS.
The key here is to name a host, otherwise the ingress rule applies to the default server, which is configured to redirect HTTP to HTTPS by default.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: foo.bar.com
http:
paths:
- path: /whoop
backend:
serviceName: test-deployment-service
servicePort: 80
您应该能够禁用默认服务器的重定向行为,我还没有尝试过.
You should be able to disable the redirect behavior for the default server, bit I haven't tried that.
这篇关于为什么我的裸机kubernetes nginx Ingress控制器返回308?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!