A LoadBalancer Service publishes selected Kubernetes Pods to internet users. Kubernetes assigns the Service an internal cluster IP and provisions an external IP address through an external network load balancer. section 3.2.5
Configure the Service to control how traffic reaches the application:
- Use selector labels to target Pods; the Service selects Pods directly rather than referencing a Deployment. section 3.2.5
- Set port for the user-facing port and targetPort for the Pod’s receiving port; they may differ, such as 80 to 8080. section 3.2.5
- Route traffic only to running Pods, even while replica counts change during upgrades or rollouts. section 3.2.5
Expose a timeserver
A Service selecting timeserver Pods can expose TCP port 80 with type: LoadBalancer. After creation, kubectl get service shows an external IP, which users can query with curl. section 3.2.5
Listing 3.3 Chapter03/3.2_DeployingToKubernetes/service.yaml
apiVersion: v1
kind: Service
metadata:
name: timeserver
spec:
selector: #1
pod: timeserver-pod #1
ports:
- port: 80 #2
targetPort: 80 #3
protocol: TCP #4
type: LoadBalancer #5
The YAML listing shows the selector, port mapping, TCP protocol, and LoadBalancer type in one deployable configuration. section 3.2.5




