Kubernetes Service
A Service in Kubernetes is associated with nursing abstraction that defines a logical set of Pods and a policy by that to access them. Services alter a loose coupling between dependent Pods. A Service is outlined exploitation YAML (preferred) or JSON, like all Kubernetes objects.

Service without Selector
apiVersion: v1 kind: Service metadata: name: salesforce_drillers_service spec: ports: - port: 8080 targetPort: 31999
Service Config File with Selector
apiVersion: v1
kind: Service
metadata:
name: salesforce_drillers_service
spec:
selector:
application: "My Application" -------------------> (Selector)
ports:
- port: 8080
targetPort: 31999
Here we have a selector, so in order to transfer traffic, we need to create an endpoint manually.
apiVersion: v1
kind: Endpoints
metadata:
name: salesforce_drillers_service
subnets:
address:
"ip": "192.168.168.40" -------------------> (Selector)
ports:
- port: 8080
Here we have created an endpoint which will route the traffic to the endpoint defined as “192.168.168.40:8080”.
Multi-Port Service Creation
apiVersion: v1
kind: Service
metadata:
name: salesforce_drillers_service
spec:
selector:
application: "My Application" -------------------> (Selector)
ClusterIP: 10.3.0.42
ports:
-name: http
protocol: TCP
port: 80
targetPort: 31999
-name:https
Protocol: TCP
Port: 443
targetPort: 31998
Types of Services
ClusterIP − It helps in restricting/limiting the service within the cluster. It exposes the service among the outlined Kubernetes cluster.
spec:
type: NodePort
ports:
- port: 8080
nodePort: 31999
name: NodeportService

NodePort − It will expose the service on a static port number on the deployed node. A ClusterIP service, to which NodePort service can route, is mechanically created. The services are often accessed from outside the cluster mistreatment the NodeIP:nodePort.
spec:
ports:
- port: 8080
nodePort: 31999
name: NodeportService
clusterIP: 10.20.30.40

Load Balancer −It uses cloud providers’ load balancer. NodePort and ClusterIP services square measure created mechanically so that the external load balancer can route.
A yaml file (full service) with service type as Node Port. Try to create one yourself.
apiVersion: v1
kind: Service
metadata:
name: appname
labels:
k8s-app: appname
spec:
type: NodePort
ports:
- port: 8080
nodePort: 31999
name: omninginx
selector:
k8s-app: appname
component: nginx
env: env_name
