K8s -Services
In Kubernetes, a Service is an abstraction which defines a logical set of Pods and a policy by which to access them (sometimes this pattern is called a micro-service). The set of Pods targeted by a Service is usually determined by a selector. To learn about other ways to define Service endpoints, see Services without selectors.
For some parts of your application (for example, frontends) you may want to expose a Service onto an external IP address, that’s outside of your cluster.
Kubernetes
ServiceTypes
allow you to specify what kind of Service you want. The default isClusterIP
.
Type
values and their behaviors are:
ClusterIP
: Exposes the Service on a cluster-internal IP. Choosing this value makes the Service only reachable from within the cluster. This is the defaultServiceType
.
NodePort
: Exposes the Service on each Node's IP at a static port (theNodePort
). AClusterIP
Service, to which theNodePort
Service routes, is automatically created. You'll be able to contact theNodePort
Service, from outside the cluster, by requesting<NodeIP>:<NodePort>
.
LoadBalancer
: Exposes the Service externally using a cloud provider's load balancer.NodePort
andClusterIP
Services, to which the external load balancer routes, are automatically created.
ExternalName
: Maps the Service to the contents of theexternalName
field (e.g.foo.bar.example.com
), by returning aCNAME
record with its value. No proxying of any kind is set up.
Kubernetes ExternalName services and Kubernetes services with Endpoints let you create a local DNS alias to an external service. This DNS alias has the same form as the DNS entries for local services, namely
<service name>.<namespace name>.svc.cluster.local
. DNS aliases provide location transparency for your workloads: the workloads can call local and external services in the same way. If at some point in time you decide to deploy the external service inside your cluster, you can just update its Kubernetes service to reference the local version. The workloads will continue to operate without any change.