There's a big difference between plain Docker/Docker Compose and Kubernetes. In Docker, one container can reach another using the other container's name as a hostname and any port the container happens to be listening on, without any special declarations. In Kubernetes all pod-to-pod communication generally goes via a service.
Even if you're not publishing a container's ports externally, its Dockerfile will often contain an EXPOSE
declaration naming some specific ports, and you can put these in the pod and service spec. If you don't have the Dockerfile docker history
or docker inspect
could tell you. Absent even that information, you'll have to use other possibly non-technical means to find it out.
If a container doesn't accept inbound connections at all (it's a worker container for a job-queueing system, for example) you may not need a Service at all.
If you don't accept inbound connections, but still need a Service (this is a requirement when using Istio) then the Service needs to declare
type: ClusterIP
clusterIP: None
This isn't documented well, but there does turn out to be a rule in code that a Service must have at least one port without this.