Skip to content

service.yaml⚓︎

Overview⚓︎

The 'service.yaml' file is used to define a Kubernetes Service object. This file is typically used in a larger project to deploy and manage microservices in a Kubernetes cluster. The Service object enables external access to a set of Pods in the cluster.

Table of Contents⚓︎

  1. Prerequisites
  2. Usage
  3. Methods
  4. Useful details

Prerequisites⚓︎

  • Kubernetes cluster
  • Understanding of Kubernetes Service objects

Usage⚓︎

To use the 'service.yaml' file in a Kubernetes project, it should be applied using the 'kubectl apply' command. For example:

kubectl apply -f service.yaml

Methods⚓︎

The 'service.yaml' file includes the following key elements: - apiVersion: The version of the Kubernetes API used to create the Service object. - kind: Specifies the type of resource being created, in this case, a Service. - metadata: Contains the name and labels for the Service. - spec: Defines the specification for the Service, including its type, ports, and selector.

Useful details⚓︎

  • The type field in the spec section specifies the type of Service, which can be 'ClusterIP', 'NodePort', 'LoadBalancer', or 'ExternalName'.
  • The ports field under spec defines the ports that the Service will listen on and the target port within the Pods.
  • The selector field is used to select which Pods will be included in the Service based on their labels.