Bird
Raised Fist0
Kubernetesdevops~20 mins

ClusterIP service type in Kubernetes - Practice Problems & Coding Challenges

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

Choose the best description of what a ClusterIP service does inside a Kubernetes cluster.

AIt assigns a static IP address to a pod for external access.
BIt exposes the service externally using a cloud provider's load balancer.
CIt creates a DNS record that points to an external IP address outside the cluster.
DIt exposes the service on a cluster-internal IP, making it reachable only within the cluster.
Attempts:
2 left
💡 Hint

Think about whether the service is reachable from outside the cluster or only inside.

💻 Command Output
intermediate
1:00remaining
What is the output of this command showing a ClusterIP service?

Given the command kubectl get svc my-service with this output, what is the ClusterIP address?

Kubernetes
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
my-service   ClusterIP   10.96.123.45    <none>        80/TCP     5m
A10.96.123.45
Bmy-service
C80/TCP
D<none>
Attempts:
2 left
💡 Hint

Look for the column labeled 'CLUSTER-IP'.

❓ Configuration
advanced
2:00remaining
Identify the correct YAML snippet for a ClusterIP service

Which YAML snippet correctly defines a Kubernetes service of type ClusterIP exposing port 8080?

A
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: ClusterIP
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080
B
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: LoadBalancer
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080
C
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080
D
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080
Attempts:
2 left
💡 Hint

Check the type field for the service type.

❓ Troubleshoot
advanced
1:30remaining
Why can't pods outside the cluster access a ClusterIP service?

You created a ClusterIP service, but external clients cannot reach it. What is the reason?

AThe service port is not open on the pod's container.
BThe service selector labels do not match any pods.
CClusterIP services are only accessible inside the cluster network, not from outside.
DThe pod is not running.
Attempts:
2 left
💡 Hint

Think about the network scope of ClusterIP services.

✅ Best Practice
expert
2:00remaining
Which practice ensures stable internal communication using ClusterIP services?

To maintain stable communication between pods using a ClusterIP service, what is the best practice?

AExpose the service as LoadBalancer for internal traffic.
BUse the service's DNS name instead of pod IPs directly.
CUse pod IP addresses directly for communication.
DRestart pods frequently to refresh connections.
Attempts:
2 left
💡 Hint

Consider what changes when pods restart or reschedule.

Practice

(1/5)
1. What is the primary purpose of a ClusterIP service in Kubernetes?
easy
A. To create a load balancer outside the cluster
B. To expose the service to the internet with a public IP
C. To assign a static external IP to the service
D. To provide an internal IP for pods to communicate within the cluster

Solution

  1. Step 1: Understand ClusterIP service role

    ClusterIP is designed to create an internal IP address accessible only inside the Kubernetes cluster.
  2. Step 2: Compare with other service types

    Other types like NodePort or LoadBalancer expose services externally, but ClusterIP does not.
  3. Final Answer:

    To provide an internal IP for pods to communicate within the cluster -> Option D
  4. Quick Check:

    ClusterIP = internal communication [OK]
Hint: ClusterIP is for internal pod communication only [OK]
Common Mistakes:
  • Confusing ClusterIP with LoadBalancer or NodePort
  • Thinking ClusterIP exposes service externally
  • Assuming ClusterIP assigns static external IP
2. Which of the following YAML snippets correctly defines a ClusterIP service?
easy
A. apiVersion: v1 kind: Pod metadata: name: my-service spec: containers: - name: myapp image: nginx
B. apiVersion: v1 kind: Service metadata: name: my-service spec: type: NodePort selector: app: myapp ports: - protocol: TCP port: 80 targetPort: 8080
C. apiVersion: v1 kind: Service metadata: name: my-service spec: type: ClusterIP selector: app: myapp ports: - protocol: TCP port: 80 targetPort: 8080
D. apiVersion: v1 kind: Service metadata: name: my-service spec: type: LoadBalancer selector: app: myapp ports: - protocol: UDP port: 80 targetPort: 8080

Solution

  1. Step 1: Check service type and selector

    apiVersion: v1 kind: Service metadata: name: my-service spec: type: ClusterIP selector: app: myapp ports: - protocol: TCP port: 80 targetPort: 8080 uses type: ClusterIP and has a proper selector and ports defined.
  2. Step 2: Validate other options

    apiVersion: v1 kind: Service metadata: name: my-service spec: type: NodePort selector: app: myapp ports: - protocol: TCP port: 80 targetPort: 8080 uses NodePort, not ClusterIP. apiVersion: v1 kind: Pod metadata: name: my-service spec: containers: - name: myapp image: nginx is a Pod, not a Service. apiVersion: v1 kind: Service metadata: name: my-service spec: type: LoadBalancer selector: app: myapp ports: - protocol: UDP port: 80 targetPort: 8080 uses type: LoadBalancer, not ClusterIP.
  3. Final Answer:

    YAML with type ClusterIP, selector, and TCP port -> Option C
  4. Quick Check:

    Correct YAML = apiVersion: v1 kind: Service metadata: name: my-service spec: type: ClusterIP selector: app: myapp ports: - protocol: TCP port: 80 targetPort: 8080 [OK]
Hint: ClusterIP service YAML must specify type: ClusterIP [OK]
Common Mistakes:
  • Using wrong service type like NodePort
  • Confusing Pod definition with Service
  • Omitting service type field
3. Given this service YAML with type ClusterIP, what will be the output of kubectl get svc my-service?
medium
A. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE my-service ClusterIP 10.96.0.1 <none> 80/TCP 5m
B. NAME TYPE EXTERNAL-IP PORT(S) AGE my-service LoadBalancer 192.168.1.1 80/TCP 5m
C. Error: service not found
D. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE my-service NodePort 10.96.0.1 <none> 80:30080/TCP 5m

Solution

  1. Step 1: Understand ClusterIP service output

    ClusterIP services show a cluster internal IP and no external IP.
  2. Step 2: Match output format

    NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE my-service ClusterIP 10.96.0.1 <none> 80/TCP 5m shows ClusterIP type with a cluster IP and <none> external IP, matching expected output.
  3. Final Answer:

    Service listed with ClusterIP and no external IP -> Option A
  4. Quick Check:

    ClusterIP service output = NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE my-service ClusterIP 10.96.0.1 <none> 80/TCP 5m [OK]
Hint: ClusterIP services have no external IP in kubectl output [OK]
Common Mistakes:
  • Expecting external IP for ClusterIP service
  • Confusing LoadBalancer or NodePort output
  • Assuming service not found error
4. You created a ClusterIP service but pods cannot reach it. Which YAML mistake could cause this?
medium
A. Using type: LoadBalancer instead of ClusterIP
B. Missing or incorrect selector labels in the service spec
C. Specifying targetPort as a string instead of a number
D. Omitting the metadata section

Solution

  1. Step 1: Identify service selector role

    The selector connects the service to the correct pods. If missing or wrong, no pods match.
  2. Step 2: Evaluate other options

    Type LoadBalancer changes exposure but doesn't block pod access. targetPort as string is accepted. metadata omission causes other errors but not pod reachability.
  3. Final Answer:

    Missing or incorrect selector labels -> Option B
  4. Quick Check:

    Selector connects pods = Missing or incorrect selector labels in the service spec [OK]
Hint: Check selector labels to link service and pods [OK]
Common Mistakes:
  • Ignoring selector labels importance
  • Blaming service type for pod connectivity
  • Confusing metadata omission with connectivity issues
5. You want to expose a web app only inside your Kubernetes cluster using a ClusterIP service. Which combination of YAML fields ensures this?
hard
A. spec: type: ClusterIP selector: app: webapp ports: - port: 80 targetPort: 8080
B. spec: type: NodePort selector: app: webapp ports: - port: 80 targetPort: 8080
C. spec: type: LoadBalancer selector: app: webapp ports: - port: 80 targetPort: 8080
D. spec: ports: - port: 80 targetPort: 8080

Solution

  1. Step 1: Confirm service type for internal exposure

    ClusterIP is the default and only exposes service inside the cluster.
  2. Step 2: Verify selector and ports

    Selector must match pods, and ports must map correctly for traffic routing.
  3. Final Answer:

    YAML with type ClusterIP, correct selector, and ports -> Option A
  4. Quick Check:

    ClusterIP + selector + ports = spec: type: ClusterIP selector: app: webapp ports: - port: 80 targetPort: 8080 [OK]
Hint: Use type ClusterIP with correct selector for internal-only service [OK]
Common Mistakes:
  • Using NodePort or LoadBalancer for internal-only access
  • Omitting service type defaults to ClusterIP but unclear
  • Incorrect or missing selector causing no pod matching
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