Skip to content
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

Support config flag for disabling HostPortManager #3914

Closed
ppmathis opened this issue Jun 30, 2020 · 11 comments
Closed

Support config flag for disabling HostPortManager #3914

ppmathis opened this issue Jun 30, 2020 · 11 comments
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@ppmathis
Copy link

Description
While setting up Cilium 1.8 according to their official documentation on a fresh Kubernetes 1.18 dual-stack cluster with cri-o 1.18.2, I've noticed that the provided connectivity test pods by Cilium 1.8 kept failing their liveness/readiness probes and ended up crashing over and over again.

The culprit turned out to be the pod for echo-b, which was stuck on ContainerCreating with the following error message taken from kubectl describe pod <echo-b-instance>:

Warning FailedCreatePodSandBox 3m (x515 over 140m) kubelet, k8s-worker1 (combined from similar events): Failed to create pod sandbox: rpc error: code = Unknown desc = failed to add hostport mapping for sandbox k8s_echo-b-659766fb56-q6krf_default_23315f9c-9555-4c0c-8388-f1f21d86df38_0(90b3292f8b0b8596cc737018a362aa6fc5daccbcec65fe5b80a2192613289ef5): HostPortManager IP family mismatch: <redacted>::7f76, isIPv6 - true

After a discussion with one of the Cilium maintainers on their Slack channel, I realized that cri-o was the culprit. When Cilium is being installed in kube-proxy-replacement mode (= no kube-proxy installed), it will also manage HostPort mappings itself using eBPF. I first assumed that cri-o would deploy a hostport CNI plugin by default which I would just have to disable, but then realized that cri-o always interacts with HostPortManager (k8s.io/kubernetes/pkg/kubelet/dockershim/network/hostport) in the sandbox code:

func convertPortMappings(in []*pb.PortMapping) []*hostport.PortMapping {
out := make([]*hostport.PortMapping, 0, len(in))
for _, v := range in {
if v.HostPort <= 0 {
continue
}
if v.Protocol != pb.Protocol_TCP && v.Protocol != pb.Protocol_UDP {
continue
}
out = append(out, &hostport.PortMapping{
HostPort: v.HostPort,
ContainerPort: v.ContainerPort,
Protocol: v1.Protocol(v.Protocol.String()),
HostIP: v.HostIp,
})
}
return out
}

portMappings := convertPortMappings(sbox.Config().GetPortMappings())
portMappingsJSON, err := json.Marshal(portMappings)
if err != nil {
return nil, err
}
g.AddAnnotation(annotations.PortMappings, string(portMappingsJSON))

Expected results
I expected cri-o to not interact with HostPortManager by default as this will break Cilium (or any other CNI which desires to handle hostport mappings by itself). I am not able to understand this behavior as it seems like the job of the CNI to do such a thing, but I unfortunately was not able to find any documentation why this code has been introduced.

Actual results
cri-o unconditionally parses the port mappings of a pod and interacts with HostPortManager to setup HostPort mappings by itself. I continued by compiling my own static build of cri-o, where I've added this hacky snippet

	log.Infof(ctx, "runSandbox: resetting parsed hostport mappings: %s", string(portMappings))
	portMappings = []*hostport.PortMapping{}
	portMappingsJSON, err = json.Marshal(portMappings)
	if err != nil {
		return nil, err
	}

before this

g.AddAnnotation(annotations.PortMappings, string(portMappingsJSON))
line from the cri-o sources.

I was able to confirm that disabling the automated mapping resolved the issues I've had with Cilium and that cri-o indeed attempted to create a mapping based on this log message I've seen: RunSandbox: resetting parsed hostport mappings: [(*hostport.PortMapping=&{ 40000 80 TCP })]

Output of crio --version:

crio version 1.18.2
Version:       1.18.2
GitCommit:     7f261aeebffed079b4475dde8b9d602b01973d33
GitTreeState:  clean
BuildDate:     2020-06-18T21:05:27Z
GoVersion:     go1.14
Compiler:      gc
Platform:      linux/amd64
Linkmode:      static

Suggestion
I assume that this automated mapping is being relied upon by a certain set of users, so patching it out completely would probably not be the best choice. I suggest to add a configuration flag to cri-o which would allow to disable this HostPortManager integration completely, as this would allow ensuring compatibility with other CNIs like Cilium.

@haircommander
Copy link
Member

thanks for opening an issue @ppmathis . We'd certainly consider adding a CLI flag that would gate this behaviour. Considering you've already dived in the code a bit, would you have any interest spinning up a PR?

@ppmathis
Copy link
Author

ppmathis commented Jul 1, 2020

would you have any interest spinning up a PR?

Sure! I've started working on a PR and will get one submitted in the next couple days. Code should be done, but testing, updating docs and those things are pending.

@haircommander
Copy link
Member

would you have any interest spinning up a PR?

Sure! I've started working on a PR and will get one submitted in the next couple days. Code should be done, but testing, updating docs and those things are pending.

excellent to hear! thanks

@haircommander haircommander added good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Jul 7, 2020
@Pranav2612000
Copy link

Has this issue been fixed? I'll like to work on this

@haircommander
Copy link
Member

it has not been, and it'd be great if you could pick it up! thanks @Pranav2612000

@github-actions
Copy link

A friendly reminder that this issue had no activity for 30 days.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 30, 2022
@haircommander
Copy link
Member

@Pranav2612000 did you still want to work on this?

@saschagrunert saschagrunert removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 14, 2022
@github-actions
Copy link

A friendly reminder that this issue had no activity for 30 days.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 14, 2023
@hasan4791
Copy link
Contributor

I can take up this issue meanwhile. Any words @haircommander

@haircommander
Copy link
Member

sounds great! it's yours :)

hasan4791 added a commit to hasan4791/cri-o that referenced this issue Feb 4, 2023
…n CRI-O

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
hasan4791 added a commit to hasan4791/cri-o that referenced this issue Feb 5, 2023
…n CRI-O

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
hasan4791 added a commit to hasan4791/cri-o that referenced this issue Feb 6, 2023
…n CRI-O

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
hasan4791 added a commit to hasan4791/cri-o that referenced this issue Feb 7, 2023
…n CRI-O

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
hasan4791 added a commit to hasan4791/cri-o that referenced this issue Mar 1, 2023
Add DisableHostportMapping option to configuration,
allowing users to disable hostport mapping for pods,
which can be useful when other services provide it other than kube-proxy (like Cillium)

Closes: cri-o#3914

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
oscrx pushed a commit to oscrx/cri-o that referenced this issue Apr 26, 2023
Add DisableHostportMapping option to configuration,
allowing users to disable hostport mapping for pods,
which can be useful when other services provide it other than kube-proxy (like Cillium)

Closes: cri-o#3914

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
oscrx pushed a commit to oscrx/cri-o that referenced this issue Apr 26, 2023
Add DisableHostportMapping option to configuration,
allowing users to disable hostport mapping for pods,
which can be useful when other services provide it other than kube-proxy (like Cillium)

Closes: cri-o#3914

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
oscrx pushed a commit to oscrx/cri-o that referenced this issue Apr 26, 2023
Add DisableHostportMapping option to configuration,
allowing users to disable hostport mapping for pods,
which can be useful when other services provide it other than kube-proxy (like Cillium)

Closes: cri-o#3914

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
hasan4791 added a commit to hasan4791/cri-o that referenced this issue Apr 26, 2023
Add DisableHostportMapping option to configuration,
allowing users to disable hostport mapping for pods,
which can be useful when other services provide it other than kube-proxy (like Cillium)

Closes: cri-o#3914

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
hasan4791 added a commit to hasan4791/cri-o that referenced this issue Apr 26, 2023
allowing users to disable hostport mapping for pods,
which can be useful when other services provide it other than kube-proxy (like Cillium)

Closes: cri-o#3914

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
hasan4791 added a commit to hasan4791/cri-o that referenced this issue Apr 26, 2023
Add DisableHostportMapping option to configuration,
allowing users to disable hostport mapping for pods,
which can be useful when other services provide it other than kube-proxy (like Cillium)

Closes: cri-o#3914

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
hasan4791 added a commit to hasan4791/cri-o that referenced this issue Apr 26, 2023
Add DisableHostportMapping option to configuration,
allowing users to disable hostport mapping for pods,
which can be useful when other services provide it other than kube-proxy (like Cillium)

Closes: cri-o#3914

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
oscrx pushed a commit to oscrx/cri-o that referenced this issue May 6, 2023
Add DisableHostportMapping option to configuration,
allowing users to disable hostport mapping for pods,
which can be useful when other services provide it other than kube-proxy (like Cillium)

Closes: cri-o#3914

Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
@haircommander haircommander removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 24, 2023
@github-actions
Copy link

A friendly reminder that this issue had no activity for 30 days.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

No branches or pull requests

5 participants