Forward all service ports to a singe container

4/1/2020

I would like to run a container in kubernetes with a static ip. I found out that only a service can provide an ip address.

Is it possible to map a Service to one pod and forward all ports?

-- Mr Mueseli
docker
kubernetes
networking

1 Answer

4/1/2020

A service discovers pods based on labels and selectors. So it is not necessary to use an IP Address to statically reference a pod from a service. However, if you so wish, you can override the autonomy behind this and manually configure your own ClusterIP for the service.

Once the Pod and Service have been created, other pods in your cluster will be able to interact with the pod via the Name of the Service provided they are in the same namespace. If they are not, you will need to pass the FQDN of the service.

If you are trying to access the pod from outside of Kubernetes, then you will need to use a Service with a different type than ClusterIP. For example, a NodePort or a LoadBalancer. Alternatively, if you have an Ingress Controller with a gateway already provisioned you could use that.

With regards to you desire to forward all ports, this is not possible as port declarations in Service files must be statically mapped. It is not currently possible to pass a Port Range but there is a long standing feature request for it.

-- TJ Zimmerman
Source: StackOverflow