Skip to content

feat : enable support for "hostNetwork" in Prometheus CRD#5010

Merged
simonpasquier merged 1 commit intoprometheus-operator:mainfrom
monitoring-projects:prometheus-hostNetwork-support
Oct 5, 2022
Merged

feat : enable support for "hostNetwork" in Prometheus CRD#5010
simonpasquier merged 1 commit intoprometheus-operator:mainfrom
monitoring-projects:prometheus-hostNetwork-support

Conversation

@rajpratik71
Copy link
Contributor

@rajpratik71 rajpratik71 commented Sep 11, 2022

Description

Enabled support for "hostNetwork" in Prometheus Operator for Prometheus

Needed in many scenarios like:

  1. To bypass the CNI network
  2. In general to reduce the metrics traffic overhead on CNI network in clusters with large no of Nodes.

Signed-off-by: Pratik Raj rajpratik71@gmail.com

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.

feat : enable support for "hostNetwork" in Prometheus CRD

Fixes #2630

@rajpratik71 rajpratik71 requested a review from a team as a code owner September 11, 2022 21:40
@rajpratik71
Copy link
Contributor Author

Failing build of "checks / Check Documentation formatting and links (pull_request)" is unrelated, i checked it is failing while opening a link which is taking long time while opening.

@slashpai
Copy link
Contributor

There is already discussion around hostNetwork support in #2630 and I see that is added in agenda for next office hours meeting

Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never used hostNetwork: true but I think that the operator needs to modify the container's ports defintion.

From the ContainerPort documentation:

hostPort | Number of port to expose on the host. If specified, this must be a valid port number, 0 < x < 65536. If HostNetwork is specified, this must match ContainerPort. Most containers do not need this.

@rajpratik71 rajpratik71 force-pushed the prometheus-hostNetwork-support branch 2 times, most recently from 26a5ac6 to 6cf8204 Compare September 16, 2022 15:46
@rajpratik71
Copy link
Contributor Author

I've never used hostNetwork: true but I think that the operator needs to modify the container's ports defintion.

From the ContainerPort documentation:

hostPort | Number of port to expose on the host. If specified, this must be a valid port number, 0 < x < 65536. If HostNetwork is specified, this must match ContainerPort. Most containers do not need this.

HI @simonpasquier ,

Please see the example at https://gist.github.com/Rajpratik71/632321a6fb8c6acc17593e2c887c45a9

When we specify "hostNetwork" for the Pod, there is no need to specify the "hostPort" seperately as when using "hostNetwork" , whole network namespace of Host will be shared, which will also expose the port.

See, below

image

Although, "hostNetwork" requires "dnsPolicy" to be set as "ClusterFirstWithHostNet".

So, raised a PR #5027 to "enable support for "dnsPolicy" in Prometheus CRD".

@simonpasquier
Copy link
Contributor

Although, "hostNetwork" requires "dnsPolicy" to be set as "ClusterFirstWithHostNet".
So, raised a PR #5027 to "enable support for "dnsPolicy" in Prometheus CRD".

After reviewing more carefully, I realize that we may not need to expose dnsPolicy in the CRD. If I understand correctly, hostNetwork: true and dnsPolicy: ClusterFirstWithHostNet go hand in hand so the Prometheus operator could set dnsPolicy to the correct value automatically.
In other words, is there any reason why you'd want to set dnsPolicy to another value than ClusterFirstWithHostNet with host networking?

@rajpratik71
Copy link
Contributor Author

Although, "hostNetwork" requires "dnsPolicy" to be set as "ClusterFirstWithHostNet".
So, raised a PR #5027 to "enable support for "dnsPolicy" in Prometheus CRD".

After reviewing more carefully, I realize that we may not need to expose dnsPolicy in the CRD. If I understand correctly, hostNetwork: true and dnsPolicy: ClusterFirstWithHostNet go hand in hand so the Prometheus operator could set dnsPolicy to the correct value automatically. In other words, is there any reason why you'd want to set dnsPolicy to another value than ClusterFirstWithHostNet with host networking?

Hi @simonpasquier , I created #5027 for the same purpose to configure the dnsPolicy . When it will get merged , i will rebase this branch to automate the process of setting "dnsPolicy" to "ClusterFirstWithHostNet" in case of "hostNetwork".

@simonpasquier
Copy link
Contributor

Sorry if I wasn't clear but my question is: do we need #5027 at all? What if the operator is the only one responsible for setting dnsPolicy?
In practice:

  • spec.hostNetwork: false (or not set) in the Prometheus CR, the operator doesn't set anything for spec.template.spec.dnsPolicy on the statefulset.
  • spec.hostNetwork: true, the operator always sets spec.template.spec.dnsPolicy: ClusterFirstWithHostNet on the statefulset.

@rajpratik71 rajpratik71 force-pushed the prometheus-hostNetwork-support branch 2 times, most recently from d673245 to acb34d6 Compare October 4, 2022 07:27
Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a unit test with "hostNetwork: true"?

@rajpratik71 rajpratik71 force-pushed the prometheus-hostNetwork-support branch from acb34d6 to f88810b Compare October 4, 2022 16:36
Enabled support for "hostNetwork" in Prometheus Operator

Needed in many scenarios like:
1. To bypass the CNI network
2. In general to reduce the metrics traffic overhead on CNI network
in clusters with large no of Nodes.

Signed-off-by: Pratik Raj <rajpratik71@gmail.com>
@rajpratik71 rajpratik71 force-pushed the prometheus-hostNetwork-support branch from f88810b to 0b343dd Compare October 4, 2022 16:38
@rajpratik71
Copy link
Contributor Author

can you add a unit test with "hostNetwork: true"?

Hi @simonpasquier , added the test for "hostNetwork: true".

Also, tested the "dnsPolicy" . it is working fine as expected.

image

Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@simonpasquier simonpasquier merged commit 036e7c4 into prometheus-operator:main Oct 5, 2022
@rajpratik71 rajpratik71 deleted the prometheus-hostNetwork-support branch October 6, 2022 03:09
rajpratik71 added a commit to rajpratik71/prometheus-community-helm-charts that referenced this pull request Nov 16, 2022
…s" CR Object

fixes prometheus-community#2689

Released in [v0.60.0](https://github.com/prometheus-operator/prometheus-operator/releases/tag/v0.60.0)

Added at [feat : enable support for "hostNetwork" in Prometheus CRD](prometheus-operator/prometheus-operator#5010)

Signed-off-by: Pratik Raj <rajpratik71@gmail.com>
rajpratik71 added a commit to rajpratik71/prometheus-community-helm-charts that referenced this pull request Nov 16, 2022
…s" CR Object

fixes prometheus-community#2689

Released in [v0.60.0](https://github.com/prometheus-operator/prometheus-operator/releases/tag/v0.60.0)

Added at [feat : enable support for "hostNetwork" in Prometheus CRD](prometheus-operator/prometheus-operator#5010)

Signed-off-by: Pratik Raj <rajpratik71@gmail.com>
monotek pushed a commit to prometheus-community/helm-charts that referenced this pull request Nov 16, 2022
…s" CR Object (#2693)

fixes #2689

Released in [v0.60.0](https://github.com/prometheus-operator/prometheus-operator/releases/tag/v0.60.0)

Added at [feat : enable support for "hostNetwork" in Prometheus CRD](prometheus-operator/prometheus-operator#5010)

Signed-off-by: Pratik Raj <rajpratik71@gmail.com>

Signed-off-by: Pratik Raj <rajpratik71@gmail.com>
Matiasmct pushed a commit to giffgaff/prometheus-charts-backup that referenced this pull request May 16, 2023
…s" CR Object (prometheus-community#2693)

fixes prometheus-community#2689

Released in [v0.60.0](https://github.com/prometheus-operator/prometheus-operator/releases/tag/v0.60.0)

Added at [feat : enable support for "hostNetwork" in Prometheus CRD](prometheus-operator/prometheus-operator#5010)

Signed-off-by: Pratik Raj <rajpratik71@gmail.com>

Signed-off-by: Pratik Raj <rajpratik71@gmail.com>
galina-tochilkin pushed a commit to mtp-devops/3d-party-helm that referenced this pull request Aug 23, 2023
…s" CR Object (#2693)

fixes #2689

Released in [v0.60.0](https://github.com/prometheus-operator/prometheus-operator/releases/tag/v0.60.0)

Added at [feat : enable support for "hostNetwork" in Prometheus CRD](prometheus-operator/prometheus-operator#5010)

Signed-off-by: Pratik Raj <rajpratik71@gmail.com>

Signed-off-by: Pratik Raj <rajpratik71@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support hostNetwork api in prometheus and alertmanager crds

3 participants