我正在尝试使用以下命令为我的集群设置NGINX入口控制器:
[root@onekube-ip-193-144-35-177 ~]# kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.34.1/deploy/static/provider/baremetal/deploy.yaml
哪个给我这个输出
namespace/ingress-nginx unchanged serviceaccount/ingress-nginx unchanged configmap/ingress-nginx-controller configured clusterrole.rbac.authorization.k8s.io/ingress-nginx unchanged clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx unchanged role.rbac.authorization.k8s.io/ingress-nginx unchanged rolebinding.rbac.authorization.k8s.io/ingress-nginx unchanged service/ingress-nginx-controller-admission unchanged service/ingress-nginx-controller unchanged deployment.apps/ingress-nginx-controller created validatingwebhookconfiguration.admissionregistration.k8s.io/ingress-nginx-admission configured clusterrole.rbac.authorization.k8s.io/ingress-nginx-admission unchanged clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission unchanged job.batch/ingress-nginx-admission-create unchanged job.batch/ingress-nginx-admission-patch unchanged role.rbac.authorization.k8s.io/ingress-nginx-admission unchanged rolebinding.rbac.authorization.k8s.io/ingress-nginx-admission unchanged serviceaccount/ingress-nginx-admission unchanged
然后我使用以下命令编辑ingress-nginx-controller服务:
kubectl edit svc -n ingress-nginx ingress-nginx-controller
然后我将K8S群集的外部IP添加到外部IP下,具体规格如下:
[...]
spec:
clusterIP: 10.99.1.223
externalIPs:
- 193.144.35.177
externalTrafficPolicy: Cluster
ports:
[...]
为了测试NGINX入口控制器是否正常工作,我现在应该能够浏览一个指向K8S群集IP地址的子域(例如prometheus.grapevine-project.eu)(由DNS查找确认) ),并且URL应该包含NGINX入口控制器返回的"404 Not Found page"
(如果确实已正确设置)。但是,我目前在Internet浏览器上看到一个"This site can’t be reached prometheus.grapevine-project.eu took too long to respond."
页面。
这是测试NGINX是否正常工作的正确/推荐方法吗?我的NGINX入口控制器设置是否可能存在任何问题?
PS
[root@onekube-ip-193-144-35-177 ~]# kubectl get svc -n ingress-nginx ingress-nginx-controller -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
ingress-nginx-controller NodePort 10.105.197.205 193.144.35.177 80:30498/TCP,443:30781/TCP 14d app.kubernetes.io/component=controller,app.kubernetes.io/instance=ingress-nginx,app.kubernetes.io/name=ingress-nginx
答案 0 :(得分:3)
无法通过注释进行故障排除,让我们通过“答案”做到这一点吗?我将根据进度编辑这篇文章。
我们可以看到type: NodePort
服务name: ingress-nginx-controller
。
这意味着您将拥有类似的东西:
ubectl get svc ingress-nginx-controller -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller NodePort 10.99.1.223 193.144.35.177 80:30498/TCP,443:30781/TCP 8m40s
我可以看到主机上的NodePort范围内恰好打开了2个端口。
PORT STATE SERVICE
30498/tcp filtered unknown
30781/tcp filtered unknown
请检查您是否能够通过CLUSTER-IP:80和CLUSTER-IP:443从群集内部访问应用程序
更新:
我刚刚复制了您的设置,就我而言,它运行良好。
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.34.1/deploy/static/provider/baremetal/deploy.yaml
$ kubectl get all -n ingress-nginx
NAME READY STATUS RESTARTS AGE
pod/ingress-nginx-admission-create-rh2b4 0/1 Completed 0 82m
pod/ingress-nginx-admission-patch-l7ttw 0/1 Completed 0 82m
pod/ingress-nginx-controller-547b58f6cb-whrck 1/1 Running 0 82m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/ingress-nginx-controller NodePort 10.0.12.124 <none> 80:31691/TCP,443:30114/TCP 82m
service/ingress-nginx-controller-admission ClusterIP 10.0.1.61 <none> 443/TCP 82m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/ingress-nginx-controller 1/1 1 1 82m
NAME DESIRED CURRENT READY AGE
replicaset.apps/ingress-nginx-controller-547b58f6cb 1 1 1 82m
NAME COMPLETIONS DURATION AGE
job.batch/ingress-nginx-admission-create 1/1 6s 82m
job.batch/ingress-nginx-admission-patch 1/1 7s 82m
$ kubectl -n ingress-nginx get ep
NAME ENDPOINTS AGE
ingress-nginx-controller 10.52.0.49:80,10.52.0.49:443 82m
ingress-nginx-controller-admission 10.52.0.49:8443 82m
即使没有编辑服务,我也可以将请求从本地PC发送到K8s群集(我的防火墙允许我这样做)。
$ curl K8S_node_IP:31691
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.19.1</center>
</body>
</html>
$ curl K8S_node_IP:30114
<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.19.1</center>
</body>
</html>
ingress-nginx-controller
是NodePort
类型的,因此在我的情况下,无需编辑它,因为我已经知道我的K8s_node_IP。
为了解决您描述的问题(服务器超时),可以执行以下操作:
kubectl
cli轻松部署。$ kubectl create deployment server-gog -n ingress-nginx --image=nkolchenko/enea:server_go_latest
deployment.apps/server-gog created
$ kubectl expose -n ingress-nginx deployment server-gog --type=NodePort --port=8180 --selector=app=server-gog
$ kubectl get svc -o wide -n ingress-nginx server-gog
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
server-gog NodePort 10.0.10.254 <none> 8180:32068/TCP 76s app=server-gog
### our app is avaliable at K8S_node_IP:32068 and 10.0.10.254:8180
$ curl K8S_node_IP:32068/some_string
Hello from ServerGo. You requested: /some_string
如果上述方法确实起作用,则问题出在您的ingress-nginx
设置内。并且需要对每个组件进行检查。
答案 1 :(得分:1)
我将尽力回答这两个问题,但这可能会使您在入口控制器完全运行之前需要做更多的工作
404
,但是即使您意识到在完成整个循环之前仍然可能会遗漏一些问题(例如SSL终止之类的东西是最明显的陷阱)但还有更多)