1
votes

I am new to kubernetes. I have created a cluster of db of kubernetes with 2 nodes. I can access those kubernetes pods from thin client like dbeaver to check the data. But I can not access those kubernetes nodes externally. I am currently trying to run a thick client which will load the data into cluster on kubernetes.

kubectl describe svc <svc>

I can see cluster-Ip assigned to the service. 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

So what is the best way to connect any node or cluster from outside.

Thank you in advance

Regards

1
how have you setup your Kubernetes cluster? if it is on some cloud provider (GKE, EKS, etc.), the loadbalancer service IP should work out of the box I believe. - Krishna Chaurasia
Not these service providers. It's internal cloud platform - iRunner
for using NodePort's IP, you'll need to create a service of type NodePort instead of LoadBalancer and then you can get the Node's IP and port from that service which you can use to connect to the service. - Krishna Chaurasia

1 Answers

0
votes

@KrishnaChaurasia is right but I would like to explain it in more detail with the help of the official docs.

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). A ClusterIP Service, to which the NodePort Service routes, is automatically created. You'll be able to contact the NodePort Service, from outside the cluster, by requesting <NodeIP>:<NodePort>. Here is an example of the NodePort Service:

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:
  • Access services through public IPs.

  • Use a service with type NodePort or LoadBalancer to make the service reachable outside the cluster. See the services and kubectl expose documentation.

  • 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. 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.

  • In most cases, it should not be necessary for application developer to directly access nodes via their nodeIPs.

  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.

These will help you to better understand the concepts of different Service Types, how to expose and access them from outside the cluster.