Skip to content
BENIBIX Learn

Kubernetes Service

Infrastructure☸️ Container OrchestrationKubernetes

Also known as K8s Service, Service (Kubernetes), ClusterIP

A steady name and address for a changing group of pods. It shares traffic among them.

Think of it like

It is like a shop's phone number. The staff change shifts, but you always call the same number.

Example

Jack's web pods call the database through a service named db. The database pod is replaced twice in a week, and the web pods never notice.

Why it matters

With no service, each app would have to chase the new address of each pod it calls.

Definition

A Kubernetes service gives a group of pods one steady name and address. Pods come and go, and each new one gets a new address. The service keeps track of which pods are alive right now. It picks them by a label, like app: shop. Any request sent to the service is passed on to one of those pods.

Example code

yaml
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app.kubernetes.io/name: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
Requests to my-service on port 80 go to any pod with the MyApp label, on port 9376.
The service sits in front of the pods. It is the one address the ingress and other apps call.

Common mistake

Sending traffic straight to a pod's address. The next time that pod is replaced, the address is gone.

Key takeaways

  1. 1
    Steady address. The name stays while pods change.
  2. 2
    Picks by label. It finds pods that carry its label.
  3. 3
    Shares the load. Requests are spread across the pods.

Compare