Sobes.tech
Middle+

What is the Service entity in Kubernetes?

sobes.tech AI

Answer from AI

In Kubernetes, the Service entity is an abstraction that defines a logical set of pods and a policy to access them. Service provides stable network access to a group of pods, hiding the dynamic nature of their IP addresses and ensuring load balancing among them.

Main types of Service:

  • ClusterIP (default) — access within the cluster via a virtual IP.
  • NodePort — opens a port on each node for external access.
  • LoadBalancer — integrates with an external load balancer.
  • ExternalName — allows referencing an external DNS resource.

Example of defining a ClusterIP type Service:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

Here, the Service directs traffic to pods with the label app: my-app, redirecting requests from port 80 to port 8080 inside the pods.

What is the Service entity in Kubernetes? — Golang - sobes.tech