Bird
0
0

Which of the following YAML snippets correctly defines a ClusterIP service?

easy📝 Configuration Q12 of 15
Kubernetes - Services
Which of the following YAML snippets correctly defines a ClusterIP service?
AapiVersion: v1 kind: Pod metadata: name: my-service spec: containers: - name: myapp image: nginx
BapiVersion: v1 kind: Service metadata: name: my-service spec: type: NodePort selector: app: myapp ports: - protocol: TCP port: 80 targetPort: 8080
CapiVersion: v1 kind: Service metadata: name: my-service spec: type: ClusterIP selector: app: myapp ports: - protocol: TCP port: 80 targetPort: 8080
DapiVersion: v1 kind: Service metadata: name: my-service spec: type: LoadBalancer selector: app: myapp ports: - protocol: UDP port: 80 targetPort: 8080
Step-by-Step Solution
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]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes