裸金属上的Nginx入口控制器暴露问题



我尝试在裸金属上部署nginx-ingress-controller,我有

4节点

  1. 10.0.76.201-节点1
  2. 10.0.76.202-节点2
  3. 10.0.76.203-节点3
  4. 10.0.76.204-节点4

4名工人

  1. 10.0.76.205-工人1
  2. 10.0.76.206-工人2
  3. 10.0.76.207-工人3
  4. 10.0.76.214-工人4

2 LB

  1. 10.0.76.208-LB 1

  2. 10.0.76.209-虚拟IP(保留(

  3. 10.0.76.210-磅10

所有东西都在BareMetal上,负载均衡器位于集群外部。

这是一个简单的haproxy配置,只需检查80端口(Worker ip(

frontend kubernetes-frontends
bind *:80
mode tcp
option tcplog
default_backend kube

backend kube
mode http
balance roundrobin
cookie lsn insert indirect nocache
option http-server-close
option forwardfor
server node-1 10.0.76.205:80 maxconn 1000 check
server node-2 10.0.76.206:80 maxconn 1000 check
server node-3 10.0.76.207:80 maxconn 1000 check
server node-4 10.0.76.214:80 maxconn 1000 check

我使用Helm安装nginx入口控制器,一切正常

NAME                                            READY   STATUS      RESTARTS   AGE
pod/ingress-nginx-admission-create-xb5rw        0/1     Completed   0          18m
pod/ingress-nginx-admission-patch-skt7t         0/1     Completed   2          18m
pod/ingress-nginx-controller-6dc865cd86-htrhs   1/1     Running     0          18m
NAME                                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
service/ingress-nginx-controller             NodePort    10.106.233.186   <none>        80:30659/TCP,443:32160/TCP   18m
service/ingress-nginx-controller-admission   ClusterIP   10.102.132.131   <none>        443/TCP                      18m
NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/ingress-nginx-controller   1/1     1            1           18m
NAME                                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/ingress-nginx-controller-6dc865cd86   1         1         1       18m
NAME                                       COMPLETIONS   DURATION   AGE
job.batch/ingress-nginx-admission-create   1/1           24s        18m
job.batch/ingress-nginx-admission-patch    1/1           34s        18m

以简单的方式部署nginx,效果良好

kubectl create deploy nginx --image=nginx:1.18
kubectl scale deploy/nginx --replicas=6
kubectl expose deploy/nginx --type=NodePort --port=80

之后,我决定创建ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tektutor-ingress 
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: "tektutor.training.org"
http:
paths:
- pathType: Prefix
path: "/nginx"
backend:
service:
name: nginx 
port:
number: 80

工作良好

kubectl describe ingress tektutor-ingress
Name:             tektutor-ingress
Labels:           <none>
Namespace:        default
Address:          10.0.76.214
Ingress Class:    <none>
Default backend:  <default>
Rules:
Host                   Path  Backends
----                   ----  --------
tektutor.training.org
/nginx   nginx:80 (192.168.133.241:80,192.168.226.104:80,192.168.226.105:80 + 3 more...)
Annotations:             kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
Events:
Type    Reason          Age                From                      Message
----    ------          ----               ----                      -------
Normal  AddedOrUpdated  18m                nginx-ingress-controller  Configuration for default/tektutor-ingress was added or updated
Normal  Sync            18m (x2 over 18m)  nginx-ingress-controller  Scheduled for sync

一切都很好,当我尝试卷曲时,任何ip都可以curl (192.168.133.241:80,192.168.226.104:80,192.168.226.105:80 + 3 more...)

现在我尝试添加主机

10.0.76.201 tektutor.training.org

这是我的主ip,在这里添加主ip正确吗?当我尝试curl tektutor.training.org不工作时

你能解释一下我最后一步有什么问题吗?我把IP设置错了?还是怎样谢谢

我希望我已经把所有的东西都写得很详尽

我曾经这个导师介质安装nginx入口控制器

TL;DR

输入如下所示的haproxy后端配置值,而不是您提供的值:

  • 30659而不是80
  • 32160而不是443(如果需要(

更多解释:

NodePort在特定的端口集上工作(默认值:30000-32767(,在这种情况下,它分配了:

  • 30659用于入口nginx控制器端口80
  • 32160用于入口nginx控制器端口443

这意味着每一个试图从外部访问集群的请求都需要联系此端口(30…(。

您可以通过以下官方文档了解更多信息:

  • Kubernetes.io:文档:概念:服务

一个花了两天时间的有趣故事:(在Ingress中,我使用了路径/nginx,但在时没有命中它

类似于:http://tektutor.training.org/nginx

那些试图掌舵我的人:(!

相关内容

  • 没有找到相关文章

最新更新