Gourav Ajmani:
Hi everyone, I have some issue in clusterIP service.
When I am try to hit the command curl clusterIP:port it’s work fine only on one node i.e node1, but when I am trying to hit the same command in another node it’s not working I.e node 2.
Can anyone assist me on this?
API version: v1
Kind: Pod
metadata:
name: myapp
labels:
app: myapp
spec:
containers:
-name: nginx
image: nginx
apiVersion: v1
kind: Service
metadata:
name: backend
spec:
type: clusterIP
ports:
-port: 80
Target port: 80
selector:
app: myapp
Andrés Torres:
ClusterIP is generally used for in-cluster communication. You need a NodePort type if you want to access the service from a specific port in all the nodes
Gourav Ajmani:
i saw some statement that clusterIP can not be accessed by external machine outside the cluster.
but i am not sure what the cluster mean here, does it mean cluster of pods or cluster of nodes.
can clusterIP (without node port) be accessed by other nodes?
Thanks
Andrés Torres:
Yes, the ClusterIP service can be accessed from other nodes in the same Cluster. In general, the way to think about it is that a Pod in the cluster can reach another Pod in the cluster using a ClusterIP service
Andrés Torres:
This is the ideal scenario for a microservice architecture: you have a backend service that is composed of several pods (a deployment) and such pods need to reach out the database pod in the same cluster, which is exposed as a service
Andrés Torres:
One of the main reasons such services are not bound to a single node is for scheduling and fault-tolerance reasons. When you create a pod, the Kubernetes scheduler decides what node is going to run such pod (although there are ways to influence this decision). If that node goes down, Kubernetes will re-schedule the pod in another node.