[英]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:我强烈建议通过以下来源:
NodePort
). 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
Access services through public IPs.通过公共 IP 访问服务。
Use a service with type NodePort
or LoadBalancer
to make the service reachable outside the cluster.使用类型为
NodePort
或LoadBalancer
的服务以使该服务可在集群外访问。 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 直接访问节点。
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.