Fix this Service that shows no endpoints.
BeginnerHands-onWrite-a-Kubernetes-manifest tasks
Answer
Broken:
apiVersion: v1
kind: Service
metadata: { name: api }
spec:
selector:
app: api
tier: backend
ports:
- port: 80
targetPort: 8000
# pods are labelled: app=api, and listen on 8080
Fixed:
spec:
selector:
app: api
ports:
- port: 80
targetPort: 8080
Check with kubectl get endpointslices -l kubernetes.io/service-name=api and kubectl get pods --show-labels.
Key trick → The selector is an AND of all labels, so the extra tier: backend matched nothing. Even after fixing that, a wrong targetPort gives connection refused. Fix both.
More on Write-a-Kubernetes-manifest tasks
Write a Deployment and Service for an Nginx app with 3 replicas, resources and probes.BeginnerAdd an HPA that scales the Deployment between 3 and 15 pods at 70% CPU.BeginnerFix this broken Deployment YAML.BeginnerWrite a ConfigMap and Secret and inject them as environment variables and as a mounted file.IntermediateWrite an Ingress that routes `/api` to the api service and `/` to the web service with TLS.IntermediateWrite a pod spec with a hardened securityContext.Intermediate