【问题标题】:Can't connect to targetPort of NodePort service无法连接到 NodePort 服务的 targetPort
【发布时间】:2022-01-15 11:30:49
【问题描述】:

我在了解集群的本地计算机上的网络时遇到了困难。我已经构建了一个简单的集群,只是为了使用 minikube 为静态文件运行 Nginx Web 服务器。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: Nginx
spec:
  selector:
    matchLabels:
      app: Nginx
  template:
    metadata:
      labels:
        app: Nginx
    spec:
      containers:
      - name: nginx
        image: pattersonbl2/webapp
        ports:
        - containerPort: 80
apiVersion: v1
kind: Service
metadata:
  name: Nginx
spec:
  selector:
    app: Nginx
  ports:
  - port: 80
    targetPort: 3088
    name: https
  type: NodePort 

这将显示在我的本地主机 IP 的 52723 端口上。我以为它会在 3088 上。您如何理解您的内容将在哪个端口上提供服务?。

【问题讨论】:

    标签: nginx kubernetes


    【解决方案1】:

    这将显示在我的 localhost IP 端口 52723 上。我认为它会 在 3088 上。您如何了解您的内容将是什么端口 服务于 ?.

    您没有在文件中设置nodePort,这意味着任何随机节点端口都将设置在 30000-32767 之间。您可以在创建时将其设置为某个值以确定节点端口。请参阅下面的说明。

    apiVersion: v1
    kind: Service
    metadata:
      name: Nginx
    spec:
      selector:
        app: Nginx
      ports:
      - port: 80              #<---This is internal port for the service which would be forwarded to targetPort
        targetPort: 3088      #<----Application is listning on this, although this seems off, typically nginx listen on 80
        nodePort: <some-port> #<----External traffic would come here, If not set random port would be set between   30000-32767. 
        name: https
      type: NodePort 
    

    【讨论】:

      猜你喜欢
      • 2021-01-02
      • 2019-04-16
      • 2022-07-17
      • 2021-05-06
      • 2021-06-27
      • 1970-01-01
      • 2020-01-24
      • 1970-01-01
      • 2018-12-20
      相关资源
      最近更新 更多