配置Ingress Kubernetes-仅在单个节点上可访问 [英] Configure Ingress Kubernetes - accessible only on single node

查看:525
本文介绍了配置Ingress Kubernetes-仅在单个节点上可访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循与此处规范相似的所有内容,在运行于VMWAre虚拟机上的Kubernetes群集上设置了入口.所有端口都是开放的,并且可以访问.

I had setup ingress on my Kubernetes Cluster running on VMWAre virtual machines by following everything similar to the specifications here. All the ports are open and accessible.

https://github.com/nginxinc/kubernetes -ingress/tree/master/examples/complete-example

我的主人是x.x.x.10,节点是x.x.x.12和x.x.x.13.

My master is x.x.x.10 and nodes are x.x.x.12 and x.x.x.13.

创建入口/控制器后,我需要获取nginx-controller运行所在的IP

After the creation of ingress/controllers, I need to get the IP where the nginx-controller runs

nginx-ingress-rc-kgfmd          1/1       Running   0          21h       172.16.5.5   x.x.x.12

因此,它通常可以在x.x.x.12或x.x.x.13上运行,然后当我执行此操作时,它将访问我的Web服务

so, it usually runs either on x.x.x.12 or x.x.x.13, and then when I do this it hits my web service

curl --resolve master.federated.fds:80:xxx12 https://master.federated.fds /咖啡

curl --resolve master.federated.fds:80:x.x.x.12 https://master.federated.fds/coffee

其中master.federated.fds是Master的DNS可解析名称.

where master.federated.fds is the DNS resolvable name of Master.

我需要使其在没有IP地址帮助的情况下工作,并且仅使用DNS可解析的名称,或者至少与任何节点ip的

I need to make it work without the help of IP address and only with the DNS resolvable name or else atleast with any of the node ip's

例如: http://node2.federated.fds/coffee ,当我卷曲时,收到连接被拒绝的错误

Eg: http://node2.federated.fds/coffee, when I curl this I get Connection refused error

更新规格

apiVersion: v1
kind: Service
metadata:
  name: coffee-svc
  labels:
    app: coffee
spec:
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
    name: http
#    nodePort: 30080
  type: NodePort
  selector:
    app: coffee

入口

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: cafe-ingress
spec:
  rules:
  - host: jciamaster.federated.fds
    http:
      paths:
      - path: /tea
        backend:
          serviceName: tea-svc
          servicePort: 80
      - path: /coffee
        backend:
          serviceName: coffee-svc
          servicePort: 80

nginxing控制器

nginx ing controller

    apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-ingress-rc
  labels:
    app: nginx-ingress
spec:
  replicas: 1
  selector:
    app: nginx-ingress
  template:
    metadata:
      labels:
        app: nginx-ingress
    spec:
      containers:
      - image: nginxdemos/nginx-ingress:0.8.1
        imagePullPolicy: Always
        name: nginx-ingress
        ports:
        - containerPort: 80
          hostPort: 80

我看到端口80仅在运行nginx pod的节点上侦听,而不在其他任何节点上侦听.有人可以让我知道如何通过所有节点ip或通过jciamaster.federated.fds之类的URL访问应用程序吗?

I see that the port 80 is listening only on the node where nginx pod runs and not on any other node. Could someone pls let me know how to access the application through all node ip's or thro a url like jciamaster.federated.fds?

谢谢

更新:

按照Marc的建议,尝试将Nginx控制器作为svc运行

Tried to run with nginx controller as svc as suggested by Marc

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-ingress-rc
  labels:
    app: nginx-ingress
spec:
  replicas: 1
  selector:
    app: nginx-ingress
  template:
    metadata:
      labels:
        app: nginx-ingress
    spec:
      containers:
      - image: nginxdemos/nginx-ingress:0.8.1
        imagePullPolicy: Always
        name: nginx-ingress
        ports:
        - containerPort: 80

        # Uncomment the lines below to enable extensive logging and/or customization of
        # NGINX configuration with configmaps
        #args:
         #- -v=3
         #- -nginx-configmaps=default/nginx-config
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: nginx-ingress-label
  name: nginx-ing-svc
spec:
  ports:
   - port: 80
     targetPort: 80
     protocol: TCP
     name: http
     nodePort: 30000
  type: NodePort
  selector:
    name: nginx-ingress

当我按下 http://xxx:30000/coffee 时,它只是挂起,什么也没做.做错了吗?

When I hit http://x.x.x.:30000/coffee it just hangs and does nothing.Anything I am doing wrong?

推荐答案

您可以使用NodePort Service公开nginx控制器Pod,然后可以在所有节点上访问它.

You can expose the nginx controller Pod with a NodePort Service, then you can access it on all nodes.

这篇关于配置Ingress Kubernetes-仅在单个节点上可访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆