我试图按照this教程来使用nginx入口控制器。一些细节已经改变,因为我试图让它工作 - 只有一个后端服务而不是两个,一些端口号和一切都在默认命名空间中运行。我在CentOS Linux版本7.4.1708虚拟机上有一个kubernetes master和3个minions。
后端和默认后端都可以通过各自的服务端点在群集中访问。 nginx状态页面在外部可用(MasterHostIP:32000 / nginx_status)。 问题是通过外部路径或从集群内部到nginx-ingress-controller-service端点拒绝对后端应用程序的http请求。 希望有人在那里可以看到一些明显我缺失的东西,或者有类似的问题并且知道如何克服这个问题。
[root@master1 ~]# kubectl get endpoints
NAME ENDPOINTS AGE
appsvc1 10.244.1.2:80,10.244.3.4:80 3h
default-backend 10.244.1.3:8080,10.244.2.3:8080,10.244.3.5:8080 14d
kubernetes 10.134.45.136:6443 15d
nginx-ingress 10.244.2.5:18080,10.244.2.5:9999 2h
[root@master1 ~]# wget 10.244.2.5:9999
--2018-01-05 12:10:56-- http://10.244.2.5:9999/
Connecting to 10.244.2.5:9999... failed: Connection refused.
[root@master1 ~]# wget 10.244.2.5:18080
--2018-01-05 12:12:52-- http://10.244.2.5:18080/
Connecting to 10.244.2.5:18080... connected.
HTTP request sent, awaiting response... 404 Not Found
2018-01-05 12:12:52 ERROR 404: Not Found.
对appsvc1端点的请求按预期运行,返回带有“Hello app1!”的静态html。
后端应用部署:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: app1
spec:
replicas: 2
template:
metadata:
labels:
app: app1
spec:
containers:
- name: app1
image: dockersamples/static-site
env:
- name: AUTHOR
value: app1
ports:
- containerPort: 80
后端服务
apiVersion: v1
kind: Service
metadata:
name: appsvc1
spec:
ports:
- port: 9999
protocol: TCP
targetPort: 80
selector:
app: app1
申请入侵
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/rewrite-target: /
name: app-ingress
spec:
rules:
- host: test.com
http:
paths:
- backend:
serviceName: appsvc1
servicePort: 9999
path: /app1
nginx入口控制器部署
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-ingress-controller
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
replicas: 1
revisionHistoryLimit: 3
template:
metadata:
labels:
app: nginx-ingress-lb
spec:
terminationGracePeriodSeconds: 60
serviceAccount: nginx
containers:
- name: nginx-ingress-controller
image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.9.0
imagePullPolicy: Always
readinessProbe:
httpGet:
path: /healthz
port: 10254
scheme: HTTP
livenessProbe:
httpGet:
path: /healthz
port: 10254
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 5
args:
- /nginx-ingress-controller
- '--default-backend-service=$(POD_NAMESPACE)/default-backend'
- '--configmap=$(POD_NAMESPACE)/nginx-ingress-controller-conf'
- --v=6
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
ports:
- containerPort: 80
- containerPort: 9999
- containerPort: 18080
nginx的-入口控制器服务
apiVersion: v1
kind: Service
metadata:
name: nginx-ingress
spec:
type: NodePort
ports:
- port: 9999
nodePort: 30000
name: http
- port: 18080
nodePort: 32000
name: http-mgmt
selector:
app: nginx-ingress-lb
nginx ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: test.com
http:
paths:
- backend:
serviceName: nginx-ingress
servicePort: 18080
更新 看起来端口9999未在入口控制器盒中打开。任何人都可以建议为什么端口18080打开但不是9999? :
[root@master1 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
app1-54cf69ff86-l7kp4 1/1 Running 0 17d
app1-54cf69ff86-qkksw 1/1 Running 0 17d
app2-7bc7498cbf-459vd 1/1 Running 0 2d
app2-7bc7498cbf-8x9st 1/1 Running 0 2d
default-backend-78484f94cf-fv6v4 1/1 Running 0 17d
default-backend-78484f94cf-vzp8l 1/1 Running 0 17d
default-backend-78484f94cf-wmjqh 1/1 Running 0 17d
nginx-ingress-controller-cfb567f76-wbck5 1/1 Running 0 15h
[root@master1 ~]# kubectl exec nginx-ingress-controller-cfb567f76-wbck5 -it bash
root@nginx-ingress-controller-cfb567f76-wbck5:/# netstat -tlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:http 0.0.0.0:* LISTEN 14/nginx: master pr
tcp 0 0 0.0.0.0:http 0.0.0.0:* LISTEN 14/nginx: master pr
tcp 0 0 0.0.0.0:https 0.0.0.0:* LISTEN 14/nginx: master pr
tcp 0 0 0.0.0.0:https 0.0.0.0:* LISTEN 14/nginx: master pr
tcp 0 0 0.0.0.0:18080 0.0.0.0:* LISTEN 14/nginx: master pr
tcp 0 0 0.0.0.0:18080 0.0.0.0:* LISTEN 14/nginx: master pr
tcp6 0 0 [::]:http [::]:* LISTEN 14/nginx: master pr
tcp6 0 0 [::]:http [::]:* LISTEN 14/nginx: master pr
tcp6 0 0 [::]:https [::]:* LISTEN 14/nginx: master pr
tcp6 0 0 [::]:https [::]:* LISTEN 14/nginx: master pr
tcp6 0 0 [::]:18080 [::]:* LISTEN 14/nginx: master pr
tcp6 0 0 [::]:18080 [::]:* LISTEN 14/nginx: master pr
tcp6 0 0 [::]:10254 [::]:* LISTEN 5/nginx-ingress-con
答案 0 :(得分:1)
10.x地址是内部的。所以404是预期的。入口控制器不会突然使您的内部服务外部。入口服务应该通过单个地址代理对已部署服务的请求。由于我看到您通过节点端口部署了控制器,尝试使用Host header test.com向节点的IP端口30000发出请求,您应该获得应用程序。您外部化的每个服务都将通过入口IP提供,主机头由HTTP客户端设置,入口控制器将基于该扇区(以及路径和您想要的任何其他内容)扇出请求。所以真的只有你支付域名才有用,因为我假设你没有自己的test.com并且要求用户伪造请求头不是一个合理的界面
此外,由于您有minion节点(复数),您应该将控制器服务类型从NodePort更改为LoadBalancer。节点端口用于教程中以便更便宜 - LoadBalancer将启动您必须支付的云负载均衡器。当你到达时,节点端口是可以的,但肯定不是你以后可以做的事情。我真的希望人们不要在没有任何解释的情况下将它放在教程中