Service

141

A Kubernetes Service is an abstraction which defines a logical set of Pods running somewhere in your cluster, that all provide the same functionality.

When created, each Service is assigned a unique IP address (also called clusterIP).

Stuff you wanna know:

  1. A network service is an abstract way to expose an application running on a set of Pods.
  2. Service is a top-level resource in the Kubernetes REST API.
  3. The set of Pods targeted by a Service is usually determined by a selector. You can define services without selectors as well.
  4. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods.
  5. If you’re able to use Kubernetes APIs for service discovery in your application, you can query the API server for Endpoints.
  6. A Service in Kubernetes is a REST object, similar to a Pod.
  7. You can POST a Service definition to the API server to create a new instance.
  8. The name of a Service object must be a valid RFC 1035 label name.
  9.  A Service can map any incoming port to a targetPort.
  10. Port definitions in Pods have names, and you can reference these names in the targetPort attribute of a Service.
  11. The default protocol for Services is TCP. Kubernetes services support UDP, SCTP, and HTTP as well.
  12. You can use TCP for any kind of Service, and it’s the default network protocol.
  13. If your cloud provider supports it, you can use a Service in LoadBalancer mode to configure a load balancer outside of Kubernetes itself, that will forward connections prefixed with PROXY protocol.
  14. Kubernetes offers a DNS cluster addon Service that automatically assigns dns names to other Services.
  15. On Windows, setting the maximum session sticky time for Services is not supported.
  16. Kubernetes lets you configure multiple port definitions on a Service object.
  17. When using multiple ports for a Service, you must give all of your ports names so that these are unambiguous.
  18. You can specify your own cluster IP address as part of a Service creation request.
  19. Kubernetes supports 2 primary modes of finding a Service – environment variables and DNS.
  20. Sometimes you don’t need load-balancing and a single Service IP. In this case, you can create what are termed “headless” Services, by explicitly specifying "None" for the cluster IP (.spec.clusterIP).
  21. Kubernetes ServiceTypes allow you to specify what kind of Service you want. The default is ClusterIP.
  22. By default, for LoadBalancer type of Services, when there is more than one port defined, all ports must have the same protocol, and the protocol must be one which is supported by the cloud provider.
  23. In a mixed environment it is sometimes necessary to route traffic from Services inside the same (virtual) network address block.
  24. In a split-horizon DNS environment you would need two Services to be able to route both external and internal traffic to your endpoints.
  25. If there are external IPs that route to one or more cluster nodes, Kubernetes Services can be exposed on thoseexternalIPs.
  26. Using the userspace proxy obscures the source IP address of a packet accessing a Service.
  27. Kubernetes allocates each Service its own IP address from within the service-cluster-ip-range CIDR range that is configured for the API server.
  28. Unlike Pod IP addresses, which actually route to a fixed destination, Service IPs are not actually answered by a single host. Instead, kube-proxy uses iptables (packet processing logic in Linux) to define virtual IP addresses which are transparently redirected as needed.

More stuff: