-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Podman play kube does not bind ports to localhost #5610
Comments
@kunalkushwaha @sujil02 Up for grabs. Or available to anyone else who wants it. |
|
@rhatdan I'll take a stab at this |
@tylarb you got it. |
@giuseppe @rhatdan I've got a few questions. First, the kubenetes API dictates that "hostPort" need not be defined: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#containerport-v1-core I would guess this is a bug inside of rootlessport - not setting a hostPort, which is interpreted as "parentPort" in rootlessport, causes it to default to 0, which is clearly invalid in rootlessport:
I could separately submit a PR to resolve this, as mapping to a host port should not be necessary for exposing a container port. I wanted to make sure this logic is correct. Can open a quick pr to rootlesskit if so. Second, as @giuseppe said, the protocol isn't set, which can be fixed, but I wondered about the implementation you might prefer. For this fix, because ctr.config.PortMappings is a slice of PortMapping, instead of a slice of pointers to PortMapping, a fix could be replacing each PortMappping with a "validated" one - i.e. adding TCP if the config is undefined.
This could be cleaner locally, but have impacts "globally" - mainly, the PortMappings for the But this could be desired - as noted, the kubernetes spec defines that if a protocol is undefined, TCP should be the default. So if it's not defined in the spec, it should be set to TCP for the |
@tylarb thanks for working on it. I think your patch is fine and we could do it in place modifying the existing slice without creating a new one. About the other issue, we need to map these concepts to Podman. What happens as root if the hostPort is not defined? |
We have a method for randomly assigning ports for use with |
@giuseppe I forgot about modifying the existing slice using the index. It's still not as clean as using a pointer but should be sufficient. As root:
This also looks to me to be incorrect - @mheon in the current design, if no hostport is specified, the json unmarshal will define it as the default value of that type - in this case, default value of int is 0, so undefined (in the yaml) hostPort == 0 |
I think we can't leave it as 0... If |
@mheon I don't think that's correct, from a kubernetes pod or podman pod perspective. In the Kubernetes API, if hostPort is unset, the container does not get a port on the host. This behavior should be the same here. I should be able to define this spec:
In this case, my app (and any helper apps) can access the DB at 5432, and serve data on the host at 8080, internally inside the pod at port 80, where "my-app-helper" processes data or something and returns it, again internally, to port 90. Neither postgres nor app-helper at bound to a host port, for security and to limit unnecessary port use. |
In that case, I don't know if we should be adding these ports to the Podman pod spec - Podman ports are exclusively host:container mappings. The expectation would be that apps connect to each other over localhost using the |
I would expect that, in the context of Podman, "containerPort" should function like an additional "expose" flag, and "hostPort" should work like a "publish" flag. The above example, not adding to pods but just the containers:
etc... |
The expose should be a no-op if the same port is already exposed in the Dockerfile though. |
For reference, |
Ah. So this is different behavior than docker? You must expose a port for a server to bind/be accessible, even inside of the container engine, at least as I recall. This is not the same in podman? I don't need to expose a port for it to be accessible by a service inside the same pod? |
Pods are sharing their network namespace, so they can access anything bound by another service in the pod via ports bound to localhost without any |
@mheon thanks so much for the clarification. In my mind then, the behavior I would expect is as follows:
I think this will still require a change to some other networking code to get the above logic correct. Does this proposal seem reasonable? |
Agree on all points - this sounds correct |
The logic used in parsing the ports to be utilized in a kubenetes api defined pod did not fully adhere to the kubenetes spec, nor did it map well to a podman context. This fix sanitizes the input of container ports to meet the following rules: - A defined containerPort with no defined hostPort does nothing in a podman context, or is informational. This is line with [usage in Kubernetes.](kubernetes/kubernetes#4332) - A defined hostPort with no defined containerPort acts like a publish [hostPort]:[hostPort] - A defined containerPort and defined hostPort works like it does in kubernetes, as in a publish [hostPort]:[containerPort] Addresses containers#5610 Signed-off-by: Tyler Ramer <[email protected]>
A friendly reminder that this issue had no activity for 30 days. |
Both issue in libpod and some parsing improvement in rootless networking
should be fixed. This can be closed now.
|
The logic used in parsing the ports to be utilized in a kubenetes api defined pod did not fully adhere to the kubenetes spec, nor did it map well to a podman context. This fix sanitizes the input of container ports to meet the following rules: - A defined containerPort with no defined hostPort does nothing in a podman context, or is informational. This is line with [usage in Kubernetes.](kubernetes/kubernetes#4332) - A defined hostPort with no defined containerPort acts like a publish [hostPort]:[hostPort] - A defined containerPort and defined hostPort works like it does in kubernetes, as in a publish [hostPort]:[containerPort] Addresses containers#5610 Signed-off-by: Tyler Ramer <[email protected]>
@tylarb
Is it supposed to work like that? Because it makes sense to me, but I'm having difficulty making it work. |
Anyone ever solve this? The simple nginx examples published on the RH blogs, followed to the letter produce the same result. The workload is not bound to the host port, thus losing it's utility. |
Setting both the containerPort and hostPort did the trick for me:
|
/kind bug
Given the following pod manifest...
produces the following output when running
podman play kube mypod.yaml
ERRO[0007] error starting some container dependencies ERRO[0007] "failed to expose ports via rootlessport: \"unknown proto: \\\"\\\"\\n\"" Error: error starting some containers: internal libpod error
Here is my version
Here is my os
The text was updated successfully, but these errors were encountered: