
Answer-first summary for fast verification
Answer: `kubectl get svc -o jsonpath='{.items[*].status.loadBalancer.ingress[0].ip}'`
The correct answer is **D** because `kubectl get svc` retrieves the service data, and `jsonpath` is used to parse the data specifically for the IP address. This method is documented in Kubernetes resources for accurately extracting service details. For example, to access services, you might use commands like: ``` export EXTERNAL_IP=$(kubectl get service bootcamp –output=jsonpath='{.status.loadBalancer.ingress[0].ip}') export PORT=$(kubectl get services –output=jsonpath='{.items[0].spec.ports[0].port}') curl "$EXTERNAL_IP:$PORT" ``` This would return the service's external IP and port, allowing you to interact with the service directly.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
You're tasked with creating a script to extract the IP address of a Kubernetes Service. Your coworker has shared a code snippet they believe could be useful. Which option would serve as the best foundation for your code?
A
kubectl get svc -o html
B
kubectl get svc
C
kubectl get svc -o filtered-json='{.items[*].status.loadBalancer.ingress[0].ip}'
D
kubectl get svc -o jsonpath='{.items[*].status.loadBalancer.ingress[0].ip}'