大网数据广告活动
服务器运维问答

Accessing kubernetes service using hostname/IP address

· 52CE 我爱测

My end goal is to be able to access exposed Kubernetes services running on on my host from another host. I am doing development in minikube and have tried using an Ingress controller. I am able to get this working on the device i…

问题原文

原帖链接 · horcle_buzz · CC BY-SA 4.0

My end goal is to be able to access exposed Kubernetes services running on on my host from another host.

I am doing development in minikube and have tried using an Ingress controller. I am able to get this working on the device itself, as per the directions here Setting up ingress on minikube. However, I want to be able to access my exposed services from a different computer, as in curl http://host.ip:8000, where host.ip is the actual public IP address of the device, not that of the minikube VM or that of an internal network created on the device; and port 8000 is that of the exposed Kubernetes service.

This does not seem like such an odd edge case, so I am surprised I not been able to find any useful information out there on how ****EASILY**** do this.

Here is my local functioning ingress controller, for completeness's sake:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nlp-adapt
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  backend:
    serviceName: default-http-backend
    servicePort: 8000
  rules:
  - host: myminikube.info
    http:
      paths:
      - path: /
        backend:
          serviceName: echoserver
          servicePort: 8080
  - host: test.nlp
    http:
      paths:
      - path: /nlptab
        backend:
          serviceName: nlptab 
          servicePort: 8000

已采纳解答

原帖链接 · Artem Golenyaev · CC BY-SA 4.0

Usually, Minikube runs inside a virtual machine. And it is necessary to expose port outside of the virtual machine additionally to exposing it outside of Kubernetes to make an application available on the host IP.

Here is the example:

  1. Expose Ingress outside of Kubernetes:

    kind: Service
    apiVersion: v1
    metadata:
      name: ingress-nginx
    spec:
      type: NodePort
      selector:
        app: ingress-nginx
      ports:
        - port: 80
          nodePort: 31080
          name: http
    
  2. Expose the 31080 port outside the Virtual machine:

    ssh -i ~/.minikube/machines/minikube/id_rsa docker@$(minikube ip) -L 31080:0.0.0.0:8000
    

After that, the application shared by Ingress will be available on http://host.ip:8000

It is not the only way to expose an application. For example, when using VirtualBox as a hypervisor, you can also use the VirtualBox NAT port forwarding feature to allow access to services exposed through NodePorts from outside. As mentioned in link provided by @horcle_buzz

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-07-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。