kubectl exec doesn't support label selectors directly. Use a subshell to grab the pod name first:
kubectl exec -it $(kubectl get pod -l app.kubernetes.io/name=api -o jsonpath='{.items[0].metadata.name}') -- bash- Multiple pods? This grabs the first one. List all with:
kubectl get pod -l app.kubernetes.io/name=api- Multi-container pod? Add
-c <container-name> - Different namespace? Add
-n <namespace>to both commands