Summary fc

position ease box interval due
front 2.35 0 0.00 2021-10-19T16:07:09Z
back 2.50 2 1.00 2021-08-08T07:51:15Z

S

ref

Definition Services in

ref Kubernetes services connect a set of pods to an abstracted service name and IP address. Services provide discovery and routing between pods. For example, services connect an application front-end to its backend, each of which running in separate deployments in a cluster. Services use labels and selectors to match pods with other applications. The core attributes of a

Kubernetes service are:

  1. A label selector that locates pods
  2. The clusterIP IP address and assigned port number
  3. Port definitions
  4. Optional mapping of incoming ports to a targetPort

Services can be defined without pod selectors. For example, to point a service to another service in a different namespace or cluster

are of 4 types

  1. ClusterIP(default). Exposes a service which is only accessible from within the cluster.
  2. NodePort. Exposes a service via a static port on each node’s IP.
  3. LoadBalancer. Exposes the service via the cloud provider’s load balancer.
  4. ExternalName. Maps a service to a predefined externalName field by returning a value for the CNAME record.

Details

Node port

NodePorts are open ports on every cluster node. Kubernetes will route traffic that comes into a NodePort to the service, even if the service is not running on that node. NodePort is intended as a foundation for other higher-level methods of ingress such as load balancers and are useful in development.

from comments answer

Load balancer

For clusters running onpublic cloud providers like AWS or Azure, creating a load LoadBalancer service provides an equivalent to a clusterIP service, extending it to an external load balancer that is specific to the cloud provider. Kubernetes will automatically create the load balancer, provide firewall rules if needed, and populate the service with the external IP address assigned by the cloud provider.

Example

Services are defined in YAML, as are all Kubernetes objects. Suppose you deployed pods running a back-end service to process data coming from a web front end. To expose a service named ‘service-backend’ on the deployment ‘deployment-backend’ you would use:

apiVersion: v1
kind: Service
metadata:
    name: service-backend # name of service
spec:
    ports:
    - port: 4000 # port of the node, external service uses this
    protocol: TCP
    targetPort: 333 # internal port
    selector:
         run: deployment-backend # pod selector
    type: ClusterIP

The service ‘service-backend’ will be created, and any pod in the cluster can access it on their port 333 via http://service-backend:4000, or at the cluster’s IP address using port 4000.

Kubernetes services can also be created using the ‘kubectl expose’ command, which does not require a YAML file. The same service can be created using the command:

kubectl expose deployment deployment-backend  - - port=333- - target-port=4000    - - name=service-backend