【问题标题】:How to response to request application by using "curl" command in kubernetes cluster nodes?如何在 Kubernetes 集群节点中使用“curl”命令响应请求应用程序?
【发布时间】:2020-09-04 06:01:03
【问题描述】:

我在 ubuntu 18.04 上构建了一个 k8s 集群(主节点 1,工作节点 5)。 我确认加入主节点和工作节点。 我使用了 kubeadm 和网络附加法兰绒。我已经部署了 nginx 服务器。

当我在集群节点上命令curl http://[cluserIP],但没有任何反应。

是k8s网络配置错了吗?

【问题讨论】:

    标签: curl networking kubernetes


    【解决方案1】:

    clusterIP 类型服务暴露的 pod 只能在集群内访问。如果您从集群中的另一个 pod 卷曲,它应该可以工作。 clusterIP 无法从集群外部访问,甚至无法从节点本身访问。如果您想通过 curl 从节点访问 pod,请通过 NodePort 服务公开它。

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service
    spec:
      type: NodePort
      selector:
        app: MyApp
      ports:
          # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
        - port: 80
          targetPort: 80
          # Optional field
          # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
          nodePort: 30007 
    

    上面的例子curl http://NODEIP:30007应该可以工作。

    【讨论】:

    • 我想使用服务,我在主节点上命令 curl。但它没有用。是网络问题?
    • 编辑问题以添加所有 yamls 和 curl 命令以及错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-12
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    相关资源
    最近更新 更多