fix: Fix a Broken Service Selector Setup & Hints

Closes #9

Signed-off-by: Abhinav Sinha <[email protected]>
This commit is contained in:
Abhinav Sinha
2026-06-09 13:23:29 +05:30
parent 17150dc856
commit a5ce787d1d
+11 -9
View File
@@ -1730,22 +1730,24 @@
"description": "## Fix a Broken Service Selector\n\nA service `my-svc` has been created but no traffic reaches the pods. The pods are labelled `app=backend`, but the service selector is misconfigured.\n\n**Your task:**\n\nFix the `my-svc` service selector so it correctly targets the `backend` pods.\n\n```bash\n# Investigate:\nkubectl describe service my-svc\nkubectl get endpoints my-svc\nkubectl get pods --show-labels\n```", "description": "## Fix a Broken Service Selector\n\nA service `my-svc` has been created but no traffic reaches the pods. The pods are labelled `app=backend`, but the service selector is misconfigured.\n\n**Your task:**\n\nFix the `my-svc` service selector so it correctly targets the `backend` pods.\n\n```bash\n# Investigate:\nkubectl describe service my-svc\nkubectl get endpoints my-svc\nkubectl get pods --show-labels\n```",
"hints": [ "hints": [
{ {
"title": "Check endpoints", "title": "Identify the mismatch",
"body": "If `kubectl get endpoints my-svc` shows `<none>`, the selector doesn't match any pods. Compare service selector with pod labels.", "body": "Check what label the pods actually carry, then compare it against the service selector.",
"command": "kubectl get endpoints my-svc" "command": "kubectl get pods --show-labels && kubectl get service my-svc -o jsonpath='{.spec.selector}'"
}, },
{ {
"title": "Patch the service selector", "title": "Patch the service selector",
"body": "Use `kubectl patch` to fix the selector.", "body": "The pods carry `app=backend` but the service selector says `app=wrong-label`. Use `kubectl patch` to point the selector at the correct label.",
"command": "kubectl patch service my-svc --type=json -p='[{\"op\":\"replace\",\"path\":\"/spec/selector/app\",\"value\":\"backend\"}]'" "command": "kubectl patch service my-svc --type=json -p='[{\"op\":\"replace\",\"path\":\"/spec/selector/app\",\"value\":\"backend\"}]'"
},
{
"title": "Verify endpoints are populated",
"body": "After fixing the selector, Kubernetes will automatically update the endpoint slice. Confirm the service now has live pod addresses.",
"command": "kubectl get endpoints my-svc"
} }
], ],
"setup_commands": [ "setup_commands": [
{ {
"command": "kubectl create deployment backend-dep --image=nginx:alpine --replicas=2 2>/dev/null || true" "command": "kubectl create deployment backend --image=nginx:alpine --replicas=2 2>/dev/null || true"
},
{
"command": "kubectl label deployment backend-dep app=backend --overwrite"
}, },
{ {
"command": "kubectl apply -f - <<EOF\napiVersion: v1\nkind: Service\nmetadata:\n name: my-svc\nspec:\n selector:\n app: wrong-label\n ports:\n - port: 80\n targetPort: 80\nEOF" "command": "kubectl apply -f - <<EOF\napiVersion: v1\nkind: Service\nmetadata:\n name: my-svc\nspec:\n selector:\n app: wrong-label\n ports:\n - port: 80\n targetPort: 80\nEOF"
@@ -1770,7 +1772,7 @@
"default_namespace": "default", "default_namespace": "default",
"teardown_commands": [ "teardown_commands": [
{ {
"command": "kubectl delete deployment backend-dep --ignore-not-found" "command": "kubectl delete deployment backend --ignore-not-found"
}, },
{ {
"command": "kubectl delete svc my-svc --ignore-not-found" "command": "kubectl delete svc my-svc --ignore-not-found"