Kubernetes与Nginx Ingress从集群外部访问。

huangapple go评论90阅读模式
英文:

kubernetes with nginx-ingress access from outside cluster

问题

以下是您提供的内容的翻译部分:

So, here is my current setup
My experience is mostly on openshift, but I'm trying to get familiar with kubernetes... and I'm a bit noob in KS8 :)

kubernets + callico + external storage(nfs) + metallb + ingress-nginx

     kubectl get nodes -o wide
    NAME        STATUS   ROLES           AGE     VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
    master01    Ready    control-plane   3d14h   v1.26.2   192.168.50.15    <none>        Ubuntu 22.04.2 LTS   5.15.0-67-generic   cri-o://1.24.4
    master02    Ready    control-plane   2d15h   v1.26.2   192.168.50.16    <none>        Ubuntu 22.04.2 LTS   5.15.0-67-generic   cri-o://1.24.4
    worker-01   Ready    worker          2d14h   v1.26.2   192.168.50.105   <none>        Ubuntu 22.04.2 LTS   5.15.0-67-generic   cri-o://1.24.4
    worker-02   Ready    worker          2d13h   v1.26.2   192.168.50.106   <none>        Ubuntu 22.04.2 LTS   5.15.0-67-generic   cri-o://1.24.4


kubectl get pods -n metallb-system -o wide

    NAME                         READY   STATUS    RESTARTS   AGE   IP               NODE        NOMINATED NODE   READINESS GATES
    controller-79d5899cb-hg4lv   1/1     Running   0          23m   10.30.0.27       worker-02   <none>           <none>
    speaker-lvpbn                1/1     Running   0          21m   192.168.50.106   worker-02   <none>           <none>
    speaker-rxcvb                1/1     Running   0          21m   192.168.50.105   worker-01   <none>           <none>

metallb has been config with this ippool

    apiVersion: metallb.io/v1beta1
    kind: IPAddressPool
    metadata:
      namespace: metallb-system
      name: lb-pool
    spec:
      addresses:
        - 192.168.50.115-192.168.50.118


 kubectl get all -n ingress-nginx

    NAME                                           READY   STATUS    RESTARTS   AGE
    pod/ingress-nginx-controller-c69664497-z84b8   1/1     Running   0          12h
    
    NAME                                         TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)                                     AGE
    service/ingress-nginx-controller             LoadBalancer   10.108.69.42    192.168.50.115   80:32481/TCP,443:32137/TCP,8443:30940/TCP   83m
    service/ingress-nginx-controller-admission   ClusterIP      10.97.240.138   <none>           443/TCP                                     12h
    
    NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
    deployment.apps/ingress-nginx-controller   1/1     1            1           12h
    
    NAME                                                 DESIRED   CURRENT   READY   AGE
    replicaset.apps/ingress-nginx-controller-c69664497   1         1         1       12h


    kubectl create deployment  httpd24 --image=docker.io/library/httpd:2.4.55
    kubectl expose deployment/httpd24 --port 80

create ingress::

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: httpd24-ingress
      namespace: default
    spec:
      ingressClassName: nginx
      rules:
      - host: http24-kube.docker-containers.local
        http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: httpd24
                port:
                  number: 80

    kubectl get ingress
    NAME              CLASS   HOSTS                                 ADDRESS          PORTS   AGE
    httpd24-ingress   nginx   http24-kube.docker-containers.local   192.168.50.115   80      58m


So, from inside cluster I can execute w/o errors curl -s http://http24-kube.docker-containers.local

However, from outside cluster ping to 192.158.50.115 or ping to http24-kube.docker-containers.local got timeout.

Computer from where I try to connect to http24-kube.docker-containers.local has access to subnet 192.168.50.0/25

I think it may be related to nginx-ingress...but have zero experience with  ....

C:\Users\AZ_fjonnas>nslookup http24-kube.docker-containers.local
Name:    http24-kube.docker-containers.local
Address:  192.168.50.115

Now, from the one of the masternodes

root@master01:~# curl -s 'http://http24-kube.docker-containers.local'
<html><body><h1>It works!</h1></body></html>
root@master01:~#

So, cluster master nodes resolve the name, moreover can access the httpd24 pod with ingress IP

But, windows machine can't access at all ingress IP(192.168.50.111) port 80

That's why I think is something related to how nginx-ingress works... :(

ALL nodes belong to same subnet: 192.168.50.0/25

希望这些翻译对您有所帮助。如果您有任何其他问题或需要进一步的帮助,请随时提出。

英文:

So, here is my current setup
My experience is mostly on openshift, but I'm trying to get familiar with kubernetes... and I'm a bit noob in KS8 Kubernetes与Nginx Ingress从集群外部访问。

kubernets + callico + external storage(nfs) + metallb + ingress-nginx

 kubectl get nodes -o wide
NAME        STATUS   ROLES           AGE     VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
master01    Ready    control-plane   3d14h   v1.26.2   192.168.50.15    &lt;none&gt;        Ubuntu 22.04.2 LTS   5.15.0-67-generic   cri-o://1.24.4
master02    Ready    control-plane   2d15h   v1.26.2   192.168.50.16    &lt;none&gt;        Ubuntu 22.04.2 LTS   5.15.0-67-generic   cri-o://1.24.4
worker-01   Ready    worker          2d14h   v1.26.2   192.168.50.105   &lt;none&gt;        Ubuntu 22.04.2 LTS   5.15.0-67-generic   cri-o://1.24.4
worker-02   Ready    worker          2d13h   v1.26.2   192.168.50.106   &lt;none&gt;        Ubuntu 22.04.2 LTS   5.15.0-67-generic   cri-o://1.24.4

kubectl get pods -n metallb-system -o wide

NAME                         READY   STATUS    RESTARTS   AGE   IP               NODE        NOMINATED NODE   READINESS GATES
controller-79d5899cb-hg4lv   1/1     Running   0          23m   10.30.0.27       worker-02   &lt;none&gt;           &lt;none&gt;
speaker-lvpbn                1/1     Running   0          21m   192.168.50.106   worker-02   &lt;none&gt;           &lt;none&gt;
speaker-rxcvb                1/1     Running   0          21m   192.168.50.105   worker-01   &lt;none&gt;           &lt;none&gt;

metallb has been config with this ippool

apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
namespace: metallb-system
name: lb-pool
spec:
addresses:
- 192.168.50.115-192.168.50.118

kubectl get all -n ingress-nginx

NAME                                           READY   STATUS    RESTARTS   AGE
pod/ingress-nginx-controller-c69664497-z84b8   1/1     Running   0          12h
NAME                                         TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)                                     AGE
service/ingress-nginx-controller             LoadBalancer   10.108.69.42    192.168.50.115   80:32481/TCP,443:32137/TCP,8443:30940/TCP   83m
service/ingress-nginx-controller-admission   ClusterIP      10.97.240.138   &lt;none&gt;           443/TCP                                     12h
NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/ingress-nginx-controller   1/1     1            1           12h
NAME                                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/ingress-nginx-controller-c69664497   1         1         1       12h
kubectl create deployment  httpd24 --image=docker.io/library/httpd:2.4.55
kubectl expose deployment/httpd24 --port 80

create ingress::

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: httpd24-ingress
namespace: default
spec:
ingressClassName: nginx
rules:
- host: http24-kube.docker-containers.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: httpd24
port:
number: 80
kubectl get ingress
NAME              CLASS   HOSTS                                 ADDRESS          PORTS   AGE
httpd24-ingress   nginx   http24-kube.docker-containers.local   192.168.50.115   80      58m

So, from inside cluster I can execute w/o errors curl -s http://http24-kube.docker-containers.local

However, from outside cluster ping to 192.158.50.115 or ping to http24-kube.docker-containers.local got timeout.

Computer from where I try to connect to http24-kube.docker-containers.local has access to subnet 192.168.50.0/25

I think it may be related to nginx-ingress...but have zero experience with ....

========

C:\Users\AZ_fjonnas&gt;nslookup http24-kube.docker-containers.local
Name:    http24-kube.docker-containers.local
Address:  192.168.50.115

Now, from the one of the masternodes

root@master01:~# curl -s &#39;http://http24-kube.docker-containers.local&#39;
&lt;html&gt;&lt;body&gt;&lt;h1&gt;It works!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;
root@master01:~#

So, cluster master nodes resolve the name, moreover can access the httpd24 pod with ingress IP

But, windows machine can't access at all ingress IP(192.168.50.111) port 80

That's why I think is something related to how nginx-ingress works... Kubernetes与Nginx Ingress从集群外部访问。

ALL nodes belong to same subnet: 192.168.50.0/25

答案1

得分: 1

抱歉,我无法理解你的请求。请提供需要翻译的文本,我会帮你进行翻译。

英文:

Damn,

Solved Kubernetes与Nginx Ingress从集群外部访问。

---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: lb-pool
namespace: metallb-system
spec:
ipAddressPools:
- lb-pool

Seems that L2Advertisement was missing according to :
https://github.com/kubernetes/ingress-nginx/blob/main/docs/deploy/baremetal.md

答案2

得分: 0

在您的机器上,除非您已将http24-kube.docker-containers.local的DNS名称指定为记录(因为这是您选择的名称,公共DNS服务器中没有相关记录),否则它无法将其解析为IP地址。如果您像下面这样添加它:

192.168.50.115	http24-kube.docker-containers.local

然后您可以执行以下操作:

curl -s http://http24-kube.docker-containers.local

或者

当您直接提供入口的IP时,需要在调用入口时指定主机标头,如下所示:

curl -s http://192.168.50.115 -H "Host: http24-kube.docker-containers.local"

注意

另外,您在Pod中尝试的命令不应该起作用,因为CoreDNS(使用默认引导配置 - Corefile)不知道如何解析http24-kube.docker-containers.local的DNS名称。

curl -s http://http24-kube.docker-containers.local

使用服务名称和命名空间组合应该起作用:

curl -s http://http24.default
英文:

In your machine, it does not know how to resolve http24-kube.docker-containers.local DNS name to an IP address unless you have specified it in /etc/hosts as a record (since it's a name chosen by you that has no records in public DNS servers). If you add it like the below:

192.168.50.115	http24-kube.docker-containers.local

Then you can do the following:

curl -s http://http24-kube.docker-containers.local

OR

You need to specify the host header when invoking the ingress while directly giving the IP of the ingress like below:

curl -s http://192.168.50.115 -H &quot;Host: http24-kube.docker-containers.local&quot;

Note

Also, The command you tried within a pod should not work since CoreDNS (with the default bootstrap configuration - Corefile) does not know what to resolve for this http24-kube.docker-containers.local DNS name.

curl -s http://http24-kube.docker-containers.local

Using service name and namespace combination should work:

curl -s http://http24.default

huangapple
  • 本文由 发表于 2023年3月7日 19:14:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75661258.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定