ClusterIP Services
Estimated time to read: 2 minutes
A ClusterIP Service provides an internal IP address that is only accessible within the Kubernetes cluster. It is the default type of service and is mainly used to expose services to other components within the cluster (like pods or other services). This type of service is not accessible from outside the cluster, making it ideal for internal communication
ClusterIP services are perfect for situations where:
- Microservices within the cluster need to communicate with each other.
- Services that don’t need to be exposed to external users but still need to be reachable within the cluster.
Imperative Method
-
Create a nginx Deployment
-
Expose the Deployment as a ClusterIP Service
kubectl expose deployment ofl-web-serve --port=80 --target-port=80 --name=my-clusterip-service --type=ClusterIP
--port
: The port that the service will expose internally.--target-port
: The port on the pod that the traffic should be forwarded to.--name
: The name of the service.--type=ClusterIP
: Ensures that the service is of type ClusterIP.
-
Verify the Service
- The ClusterIP service type does not require an
EXTERNAL-IP
because it is only accessible within the cluster. - Load balancing across multiple pods happens automatically when using services.
- The ClusterIP service type does not require an