-1

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?

AVarf
  • 4,481
  • 9
  • 47
  • 74
  • did you default port 80 – P Ekambaram Jun 17 '19 at 14:10
  • 1
    I can say this is my question (in other words) what is the default port if we don't define a port in compose file or when we use `docker run`? And to answer your question no I didn't define a default port and the compose file that I use for `docker-compose` doesn't have a port field at all. – AVarf Jun 17 '19 at 14:22

2 Answers2

3

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.

David Maze
  • 130,717
  • 29
  • 175
  • 215
1

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.

Frank Yucheng Gu
  • 1,807
  • 7
  • 21
  • 1
    I am talking about docker-compose and I want to know how can I create a service for such a container in Kubernetes. All my other containers have exposing ports in their compose files and I used those ports for my service definition but there are two that don't have ports and I found out that other components are communicating with these two via AMQP but as I said there is no explicit port exposed. At the moment I am looking to see how stuff is working under the hood for those components. – AVarf Jun 18 '19 at 07:41