The Service primitive in Kubernetes abstracts away network complexities and provides a durable endpoint for accessing pods.

NodePort Service

Allows external access to the Kubernetes network by exposing a static port on the node (range: 30000-32767).

apiVersion: v1
kind: Service
metadata:
  name: grade-submission-portal
spec:
  type: NodePort
  selector:
    app: grade-submission-portal
  ports:
    - port: 8080
      targetPort: 8080
      nodePort: 30080

Note: The NodePort service is often used when prototyping, rarely in practice.

ClusterIP Service

Used for internal pod-to-pod communication within the cluster.

apiVersion: v1
kind: Service
metadata:
  name: backend-service
spec:
  type: ClusterIP
  selector:
    app: backend
  ports:
    - port: 8080
      targetPort: 8080