简体   繁体   English

从外部访问 Kubernetes 集群/节点

[英]Access the Kubernetes cluster/node from outside

I am new to kubernetes.我是 kubernetes 的新手。 I have created a cluster of db of kubernetes with 2 nodes.我创建了一个带有 2 个节点的 kubernetes 数据库集群。 I can access those kubernetes pods from thin client like dbeaver to check the data.我可以从像 dbeaver 这样的瘦客户端访问那些 kubernetes pod 来检查数据。 But I can not access those kubernetes nodes externally.但我无法从外部访问那些 kubernetes 节点。 I am currently trying to run a thick client which will load the data into cluster on kubernetes.我目前正在尝试运行一个胖客户端,它将数据加载到 kubernetes 上的集群中。

kubectl describe svc <svc>

I can see cluster-Ip assigned to the service.我可以看到分配给服务的 cluster-Ip。 Type of my service is loadbalancer.我的服务类型是负载均衡器。 I tried to use that but still not connecting.我尝试使用它,但仍然无法连接。 I read about using nodeport but without any IP address how to access that我读到了使用 nodeport 但没有任何 IP 地址如何访问它

So what is the best way to connect any node or cluster from outside.那么从外部连接任何节点或集群的最佳方式是什么。

Thank you in advance先感谢您

Regards问候

@KrishnaChaurasia is right but I would like to explain it in more detail with the help of the official docs. @KrishnaChaurasia 是对的,但我想在官方文档的帮助下更详细地解释它。

I strongly recommend going through the following sources:我强烈建议通过以下来源:

  1. NodePort Type Service : Exposes the Service on each Node's IP at a static port (the NodePort ). NodePort 类型服务:在 static 端口( NodePort )上公开每个节点的 IP 上的服务。 A ClusterIP Service, to which the NodePort Service routes, is automatically created.自动创建NodePort服务路由到的ClusterIP服务。 You'll be able to contact the NodePort Service, from outside the cluster, by requesting <NodeIP>:<NodePort> .您可以通过请求<NodeIP>:<NodePort>从集群外部联系NodePort服务。 Here is an example of the NodePort Service:以下是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
  1. Accessing services running on the cluster : You have several options for connecting to nodes, pods and services from outside the cluster: 访问集群上运行的服务:您有多种选项可以从集群外部连接到节点、pod 和服务:
  • Access services through public IPs.通过公共 IP 访问服务。

  • Use a service with type NodePort or LoadBalancer to make the service reachable outside the cluster.使用类型为NodePortLoadBalancer的服务以使该服务可在集群外访问。 See the services and kubectl expose documentation.请参阅服务kubectl 公开文档。

  • Depending on your cluster environment, this may just expose the service to your corporate network, or it may expose it to the internet.根据您的集群环境,这可能只是将服务公开给您的公司网络,也可能将其公开给互联网。 Think about whether the service being exposed is secure.考虑暴露的服务是否安全。 Does it do its own authentication?它是否进行自己的身份验证?

  • Place pods behind services.将 pod 放在服务后面。 To access one specific pod from a set of replicas, such as for debugging, place a unique label on the pod and create a new service which selects this label.要从一组副本中访问一个特定的 pod,例如进行调试,请在 pod 上放置一个唯一的 label 并创建一个选择此 label 的新服务。

  • In most cases, it should not be necessary for application developer to directly access nodes via their nodeIPs.在大多数情况下,应用程序开发人员不需要通过其 nodeIP 直接访问节点。

  1. A supplement example: Use a Service to Access an Application in a Cluster : This page shows how to create a Kubernetes Service object that external clients can use to access an application running in a cluster.补充示例: 使用服务访问集群中的应用程序:此页面显示如何创建 Kubernetes 服务 object,外部客户端可以使用该服务访问集群中运行的应用程序。

These will help you to better understand the concepts of different Service Types, how to expose and access them from outside the cluster.这些将帮助您更好地理解不同服务类型的概念,以及如何从集群外部公开和访问它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从集群外访问 Kubernetes 中的 MongoDB - How access MongoDB in Kubernetes from outside the cluster 无法从集群外部访问 Kubernetes 仪表板 - Unable to access Kubernetes dashboard from outside the cluster 从集群外的应用程序访问 kube.netes 中的 postgres - access postgres in kubernetes from an application outside the cluster 无法从管理器访问节点应用程序Kubernetes集群 - Not access from manager to node application Kubernetes cluster 如何从Kubernetes中的群集外部访问Pod? 我将其作为节点端口服务公开,但是无法通过该节点端口访问它 - How to access pod from outside of my cluster in kubernetes? I exposed it as node port service but can't access it with that node port kube.netes,集群外访问IP - Kubernetes, access IP outside the cluster 在 VPN 外访问 kubernetes 集群 - Access kubernetes cluster outside of VPN 如何使用rabbitmqctl从RabbitMQ Kubernetes集群外部访问? - How to access from outside a RabbitMQ Kubernetes cluster using rabbitmqctl? Ubuntu:无法从集群外部访问 Kubernetes 服务 - Ubuntu: Cannot access Kubernetes service from outside cluster 如何从外部访问kubernetes集群上托管的mongodb replicaset? - How to access mongodb replicaset hosted on a kubernetes cluster from outside?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM