The Monster Market in straits-a1w5fo has three Deployments and three Services. The client Pod cannot reach any of them:
client ──▶ market-web:80 Connection refused
client ──▶ market-api:8080 Connection refused
client ──▶ market-db:5432 Connection refusedA second namespace, straits-a1w5fo-ops, has its own client that needs the API's address.
Fix the three Services
kubectl get svc -n straits-a1w5fo
kubectl describe svc -n straits-a1w5fo
kubectl get pods -n straits-a1w5fo --show-labelsEach Service has exactly one fault. Check in this order:
Endpoints: <none>? the selector does not match the Pod labels
Endpoints present,
still refused? TargetPort is not the container's port
Port wrong for the client? the client expects web on 80, api on 8080, db on 5432Container ports: web 80, api 8080, db 5432. Fix each Service by applying a full manifest with the same name:
kubectl apply -n straits-a1w5fo -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: market-db
spec:
selector:
app: market-db
ports:
- port: 5432
targetPort: 5432
EOFProve each one from the client Pod:
kubectl exec client -n straits-a1w5fo -- wget -qO- market-web
kubectl exec client -n straits-a1w5fo -- wget -qO- market-api:8080/healthz
kubectl exec client -n straits-a1w5fo -- nc -zv market-db 5432Wire up the second namespace
Create a ConfigMap api-url in straits-a1w5fo-ops whose key url holds the API's full in-cluster URL, namespace included:
kubectl create configmap api-url -n straits-a1w5fo-ops \
--from-literal=url=http://market-api.straits-a1w5fo.svc.cluster.local:8080Open the web to the outside
After its selector is fixed, apply the market-web manifest again with type: NodePort, then read the port:
kubectl get svc market-web -n straits-a1w5fo -o jsonpath='{.spec.ports[0].nodePort}'Fetch it through the node:
$ curl -s http://10.0.0.10:<that port>The last objective is a question: when the client sends a packet to a cluster IP, which component rewrites it to a Pod address?