Let’s understand what contents make a ClusterIP service and what exactly it means.
apiVersion: v1
kind: Service
metadata:
name: <service_name>
spec:
type: ClusterIP
ports:
- targetPort: 80
port: 80
selector:
name: <value>
type: <value>
- apiVersion represents from which group Kind belongs.
- kind represents the type of Kubernetes objects.
- metadata defines the details of the service, such as, what should be the name of the service, etc.
- spec defines the specification for the service.
- The service type is defined by type.
- ports, define the port on which communication establish.
- targetPort, defines the container port, on which the application is running.
- port, define for cluster mode access.
- selector, which is in charge of selecting all pods whose values are defined in the keys(name,type).
To create the service in the Kubernetes cluster run the below command
kubectl create -f <service.yaml>
MtroView team is giving its best & working hard to provide the content to help you understand things better in simple terms. We are heartily open to receiving suggestions to improve our content to help more people in society. Please write to us in the form of a comment or can also send an email to mtroview@gmail.com