Bird
Raised Fist0
Kubernetesdevops~20 mins

LoadBalancer service type in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
LoadBalancer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What does a LoadBalancer service type do in Kubernetes?

In Kubernetes, what is the main purpose of a service with type LoadBalancer?

AIt exposes the service externally using a cloud provider's load balancer and assigns a public IP.
BIt only exposes the service inside the cluster without any external access.
CIt creates a DNS record for the service but does not expose it externally.
DIt automatically scales the number of pods based on incoming traffic.
Attempts:
2 left
💡 Hint

Think about how external users can access your service from outside the cluster.

💻 Command Output
intermediate
1:30remaining
Output of kubectl get svc for LoadBalancer service

What is the expected output of kubectl get svc for a LoadBalancer service just created in a cloud environment?

Kubernetes
kubectl get svc my-loadbalancer-service
A
NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
my-loadbalancer-service NodePort       10.0.0.1       <none>           80:30080/TCP     5m
B
NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
my-loadbalancer-service LoadBalancer   10.0.0.1       <pending>        80:30080/TCP     5m
C
NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
my-loadbalancer-service ClusterIP     10.0.0.1       <none>           80/TCP           5m
D
NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
my-loadbalancer-service LoadBalancer   10.0.0.1       35.226.14.5      80:30080/TCP     5m
Attempts:
2 left
💡 Hint

Just after creation, the cloud provider has not yet provisioned the load balancer.

❓ Configuration
advanced
2:00remaining
Correct YAML for a LoadBalancer service

Which YAML snippet correctly defines a Kubernetes service of type LoadBalancer exposing port 80?

A
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: LoadBalancer
  selector:
    app: myapp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
B
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: myapp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
C
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: ClusterIP
  selector:
    app: myapp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
D
08 :troPtegrat      
08 :trop      
PCT :locotorp -    
:strop  
ppaym :ppa    
:rotceles  
recnalaBdaoL :epyt  
:ceps
ecivres-ym :eman  
:atadatem
ecivreS :dnik
1v :noisreVipa
Attempts:
2 left
💡 Hint

Check the service type and protocol used for HTTP traffic.

❓ Troubleshoot
advanced
1:30remaining
Why is EXTERNAL-IP stuck at <pending>?

You created a LoadBalancer service in Kubernetes, but kubectl get svc shows <pending> in the EXTERNAL-IP column. What is the most likely cause?

AThe pod is crashing and restarting continuously.
BThe service selector labels do not match any pods.
CThe service port is not exposed in the pod containers.
DThe Kubernetes cluster is running on a local machine or environment without a cloud provider integration.
Attempts:
2 left
💡 Hint

Think about what provisions the external IP for LoadBalancer services.

🔀 Workflow
expert
2:30remaining
Steps to expose an app externally using LoadBalancer service

What is the correct order of steps to expose a Kubernetes app externally using a LoadBalancer service?

A2,1,3,4
B3,1,2,4
C1,2,3,4
D1,3,2,4
Attempts:
2 left
💡 Hint

Create both YAML files before applying them to the cluster.

Practice

(1/5)
1. What does the LoadBalancer service type do in Kubernetes?
easy
A. It creates multiple internal IPs for the service.
B. It only exposes the service inside the cluster without external access.
C. It exposes the service externally with a cloud provider's load balancer and a single external IP.
D. It automatically scales the number of pods based on load.

Solution

  1. Step 1: Understand LoadBalancer service purpose

    The LoadBalancer service type is designed to expose a Kubernetes service externally using a cloud provider's load balancer.
  2. Step 2: Identify the external IP behavior

    It provides a single external IP address that routes traffic to the service pods.
  3. Final Answer:

    It exposes the service externally with a cloud provider's load balancer and a single external IP. -> Option C
  4. Quick Check:

    LoadBalancer = external IP + cloud load balancer [OK]
Hint: LoadBalancer = external IP + cloud load balancer [OK]
Common Mistakes:
  • Confusing LoadBalancer with ClusterIP (internal only)
  • Thinking it creates multiple external IPs
  • Assuming it auto-scales pods
2. Which of the following is the correct YAML snippet to create a LoadBalancer service in Kubernetes?
easy
A. apiVersion: v1 kind: Service metadata: name: my-service spec: type: NodePort ports: - port: 80 selector: app: my-app
B. apiVersion: v1 kind: Service metadata: name: my-service spec: type: ExternalName ports: - port: 80 selector: app: my-app
C. apiVersion: v1 kind: Pod metadata: name: my-service spec: type: LoadBalancer ports: - port: 80 selector: app: my-app
D. apiVersion: v1 kind: Service metadata: name: my-service spec: type: LoadBalancer ports: - port: 80 selector: app: my-app

Solution

  1. Step 1: Identify correct kind and type

    The resource must be kind: Service and spec.type: LoadBalancer to create a LoadBalancer service.
  2. Step 2: Check YAML correctness

    apiVersion: v1 kind: Service metadata: name: my-service spec: type: LoadBalancer ports: - port: 80 selector: app: my-app correctly uses kind: Service and type: LoadBalancer with proper ports and selector.
  3. Final Answer:

    YAML with kind: Service and type: LoadBalancer -> Option D
  4. Quick Check:

    LoadBalancer service YAML uses kind: Service + type: LoadBalancer [OK]
Hint: LoadBalancer service YAML: kind Service + type LoadBalancer [OK]
Common Mistakes:
  • Using kind: Pod instead of Service
  • Using wrong service type like NodePort or ExternalName
  • Missing selector or ports section
3. Given this service YAML with type LoadBalancer, what will kubectl get svc my-service show for the EXTERNAL-IP field after creation?
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: my-app
medium
A. An external IP address like 34.68.123.45
B. <none>
C. Pending
D. ClusterIP address like 10.0.0.1

Solution

  1. Step 1: Understand LoadBalancer external IP assignment

    When a LoadBalancer service is created, the cloud provider assigns an external IP address to the service, visible in EXTERNAL-IP field.
  2. Step 2: Recognize typical EXTERNAL-IP values

    Initially, EXTERNAL-IP may show Pending, but after provisioning, it shows an actual external IP like 34.68.123.45.
  3. Final Answer:

    An external IP address like 34.68.123.45 -> Option A
  4. Quick Check:

    LoadBalancer EXTERNAL-IP = cloud IP address [OK]
Hint: LoadBalancer EXTERNAL-IP shows cloud IP, not ClusterIP [OK]
Common Mistakes:
  • Expecting <none> or ClusterIP in EXTERNAL-IP field
  • Confusing Pending state as final
  • Thinking LoadBalancer does not assign external IP
4. You created a LoadBalancer service but kubectl get svc shows EXTERNAL-IP as "Pending" indefinitely. What is the most likely cause?
medium
A. The Kubernetes cluster is not running on a cloud provider that supports LoadBalancer.
B. The service selector does not match any pods.
C. The service type is incorrectly set to ClusterIP.
D. The pod containers do not expose the correct port.

Solution

  1. Step 1: Understand LoadBalancer external IP provisioning

    LoadBalancer service requires cloud provider support to provision an external IP and load balancer.
  2. Step 2: Identify cause of Pending EXTERNAL-IP

    If the cluster runs on bare metal or unsupported environment, the external IP stays Pending indefinitely.
  3. Final Answer:

    The Kubernetes cluster is not running on a cloud provider that supports LoadBalancer. -> Option A
  4. Quick Check:

    Pending EXTERNAL-IP means no cloud LB support [OK]
Hint: Pending EXTERNAL-IP means no cloud load balancer support [OK]
Common Mistakes:
  • Blaming pod selector or ports for EXTERNAL-IP Pending
  • Confusing service type ClusterIP with LoadBalancer
  • Ignoring cluster environment limitations
5. You want to expose a Kubernetes app externally with a LoadBalancer service, but your cluster runs on bare metal without cloud support. Which approach will work best?
hard
A. Use ClusterIP service type and access pods internally only.
B. Change service type to NodePort and use external node IP with the node port.
C. Use LoadBalancer service type and wait for external IP assignment.
D. Delete the service and expose pods directly with hostPort.

Solution

  1. Step 1: Recognize LoadBalancer limitation on bare metal

    LoadBalancer service requires cloud provider support, which bare metal lacks, so it won't get an external IP.
  2. Step 2: Choose alternative external exposure method

    NodePort exposes the service on each node's IP at a static port, allowing external access without cloud load balancer.
  3. Final Answer:

    Change service type to NodePort and use external node IP with the node port. -> Option B
  4. Quick Check:

    Bare metal + external access = NodePort service [OK]
Hint: Bare metal clusters use NodePort for external access, not LoadBalancer [OK]
Common Mistakes:
  • Expecting LoadBalancer to work without cloud support
  • Using ClusterIP which is internal only
  • Exposing pods directly with hostPort is less flexible
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard