The purpose of a Service is to set up networking in a Kubernetes cluster.

There are four types of Services.

  1. ClusterIP
  2. NodePort - Mostly used for development purposes
  3. LoadBalancer
  4. Ingress

Here’s a sample Service config file.

apiVersion: v1
kind: Service
  name: client-node-port
  # Specifying the type of Service
  type: NodePort

  # An array of ports
      # port specifies the port that other pods can access to
    - port: 3000
      # targetPort specifies the port being used for a container
      targetPort: 8080
      # nodePort specifies the port mapped to the targetPort
      nodePort: 4000

  # selector will basically look for Pods that have a matching key-value pair.
  # Pods that meet the criteria will use client-node-port as their Service.
    component: web