I am bringing an application which consists of different components to Kubernetes. Now I faced with some components that their compose file doesn't have any port and I don't know how to create a service for them. I checked those components and their network settings are as below:
"NetworkSettings": {
"Bridge": "",
"Ports": {},
"Gateway": "172.18.133.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.18.133.14",
[other-configs]
}
How can we create services for these kind of components?
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.
Assuming you are talking about public access, according to the docker documentation,
By default, when you create a container, it does not publish any of its ports to the outside world. To make a port available to services outside of Docker, or to Docker containers which are not connected to the container’s network, use the --publish or -p flag.
If you are referring to inter-container communication on docker-compose, you will have to check your application as ports do not require "exposing" on the docker network.