**### Description:
- Kubernetes Object
- Service is a method for exposing a network application that is running as one or more pods in your cluster
Services in K8s
.
- each service object defines a logical set of endpoints (usually pods) along with a policy about how to make those pods accessible
Cloud-native service discovery:
Defining a service:
Relaxed naming requirements for Service object:
Port definitions
Service type (CLEN):
ClusterIP
- An IP in cluster, that forward ClusterIP:port to pod:targetPort
NodePort
- Same as ClusterIP, but every nodes also allocate a port (NodePort) and they are pointed to the service with
port(then it is forward to pod:targetPort) - nodeport is specified by
--service-node-port-rangeflag (default: 30000-32767)
LoadBalancer
- Load balancer
- Using NodePort, every node has different IP → annoying
- LB built on top of NodePort
- user access LoadBalancer:80 → NodePort:31000 → ClusterIP:80 → Pod:80
ExternalName
- Map normal name to external name, example: db-url to gcloud db
API
- apiVersion: v1
- kind: Service
- metadata
- spec: ServiceSpec
- status: ServiceStatus
ServiceSpec
- selector: map[string]string
- ports:
- port
- targetPort
- protocol
- name
- nodePort: optional for NodePort or LoadBalancer only
- type: 1 of the 4 (CLEN) types