0
0
Kubernetesdevops~10 mins

LoadBalancer service type in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - LoadBalancer service type
Create Service YAML with type LoadBalancer
kubectl apply -f service.yaml
Kubernetes requests cloud provider
Cloud provider provisions external LoadBalancer
External IP assigned to Service
Clients access Service via External IP
LoadBalancer forwards traffic to Pods
Service works
This flow shows how creating a LoadBalancer service in Kubernetes triggers cloud provider actions to expose the service externally.
Execution Sample
Kubernetes
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: LoadBalancer
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
This YAML defines a LoadBalancer service exposing pods with label app=my-app on port 80 externally.
Process Table
StepActionKubernetes StateCloud Provider ActionResult
1Apply service YAMLService object created with type LoadBalancerNone yetService pending external IP
2Kubernetes requests cloud providerService status pendingProvision external LoadBalancerLoadBalancer resource created
3Cloud provider creates LoadBalancerService status updatingAssign external IPExternal IP assigned to Service
4Service readyService has external IPLoadBalancer forwards trafficClients can access service externally
5Client sends requestRequest received by LoadBalancerForward to pod endpointsPods receive traffic
6Pods respondResponse sent back through LoadBalancerResponse forwarded to clientClient receives response
7EndService running with external IPLoadBalancer activeOperation complete
💡 Service has external IP and traffic flows through LoadBalancer to pods
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
Service ObjectNoneCreated with type LoadBalancerPending external IPExternal IP assignedReady with external IP
External IPNoneNoneNoneAssigned (e.g. 34.68.12.34)Assigned (e.g. 34.68.12.34)
LoadBalancer StatusNoneNoneProvisioningActiveActive
Key Moments - 3 Insights
Why does the Service not have an external IP immediately after creation?
Because Kubernetes must first request the cloud provider to create the LoadBalancer, which takes time. See execution_table step 2 and 3 where the external IP is assigned only after provisioning.
What happens if the cloud provider does not support LoadBalancer services?
The Service will remain without an external IP and stay in pending state. This is shown in execution_table step 2 where the cloud provider action is required but may not happen.
How does traffic reach the pods from the external IP?
The LoadBalancer forwards incoming traffic to the pods selected by the Service selector. This is shown in execution_table steps 5 and 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the external IP assigned to the Service?
AStep 3
BStep 5
CStep 1
DStep 7
💡 Hint
Check the 'External IP assigned to Service' result in the rows.
According to variable_tracker, what is the state of the Service Object after Step 2?
AExternal IP assigned
BCreated with type LoadBalancer
CPending external IP
DReady with external IP
💡 Hint
Look at the 'Service Object' row under 'After Step 2' column.
If the cloud provider fails to provision the LoadBalancer, what will happen to the Service status?
AService will have an external IP
BService will remain pending without external IP
CService will be deleted automatically
DService will switch to ClusterIP type
💡 Hint
Refer to key_moments about cloud provider support and execution_table step 2.
Concept Snapshot
LoadBalancer Service in Kubernetes:
- type: LoadBalancer exposes service externally
- Kubernetes requests cloud provider to create LoadBalancer
- External IP assigned after provisioning
- Traffic flows from external IP to pods
- Requires cloud provider support
Full Transcript
This visual execution shows how a Kubernetes Service of type LoadBalancer works. First, you create a Service YAML with type LoadBalancer and apply it. Kubernetes then asks the cloud provider to create an external LoadBalancer. The cloud provider provisions it and assigns an external IP to the Service. Clients can then access the Service using this external IP. The LoadBalancer forwards traffic to the pods selected by the Service. The execution table traces each step from creation to traffic flow. The variable tracker shows how the Service object and external IP change state. Key moments clarify common confusions like why the external IP is not immediate and what happens if the cloud provider does not support LoadBalancer. The quiz tests understanding of when the external IP is assigned and the Service status during provisioning.