Skip to content

feat(chart): add optional NetworkPolicy for high availability - #486

Open
DsThakurRawat wants to merge 1 commit into
kubernetes-sigs:mainfrom
DsThakurRawat:fix/480-network-policy
Open

DsThakurRawat wants to merge 1 commit into
kubernetes-sigs:mainfrom
DsThakurRawat:fix/480-network-policy

Conversation

@DsThakurRawat

Copy link
Copy Markdown
Contributor

Adds an optional NetworkPolicy to the Helm chart, disabled by default.

When networkPolicy.enabled is true, the policy selects the controller pods and allows kubelet probes (8081), the webhook port when webhook.enabled, the metrics port when metrics.enabled, plus API server (443) and DNS (53) egress. Extra ingress/egress rules can be appended verbatim via values for clusters that need more.

Verified locally: helm lint clean, helm template renders byte-identical output across runs, the podSelector matches the deployment selector exactly, all 46 helm-unittest tests pass (5 new), and hack/verify-chart-drift.sh is clean.

Fixes #480

@kubernetes-prow kubernetes-prow Bot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Sep 27, 2026
@netlify

netlify Bot commented Sep 27, 2026

Copy link
Copy Markdown

✅ Deploy Preview for node-readiness-controller canceled.

Name Link
🔨 Latest commit 5c7ebff
🔍 Latest deploy log https://app.netlify.com/projects/node-readiness-controller/deploys/6ab8d5f495a6f500089e73d7

@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: DsThakurRawat
Once this PR has been reviewed and has the lgtm label, please assign haircommander for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify

netlify Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for node-readiness-controller canceled.

Name Link
🔨 Latest commit d2646aa
🔍 Latest deploy log https://app.netlify.com/projects/node-readiness-controller/deploys/6ad64276b66b84a46d402589

@kubernetes-prow kubernetes-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 27, 2026
@kubernetes-prow

Copy link
Copy Markdown

Hi @DsThakurRawat. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 27, 2026
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Sep 27, 2026
@DsThakurRawat

Copy link
Copy Markdown
Contributor Author

waiting for feedback on this one

@DsThakurRawat
DsThakurRawat force-pushed the fix/480-network-policy branch from 18af0d7 to d35d92d Compare October 17, 2026 16:05
@sairamreddybhavanam

Copy link
Copy Markdown

Hi @DsThakurRawat, thanks for adding this. I tried it on a k3s cluster, and the default egress rule blocks the controller from reaching the API server.

The rule only allows 443. On k3s and kubeadm that endpoint is on 6443, so the traffic gets dropped.

What I tested (k3d, k3s v1.33.6+k3s1, Calico enforcing policies):

Installed the chart from this PR with networkPolicy.enabled=true, everything else default.
kubectl get endpointslices -n default -l kubernetes.io/service-name=kubernetes shows 172.19.0.2:6443.
The controller never gets its lease:

"Error retrieving lease lock" err="Get "https://10.43.0.1:443/apis/coordination.k8s.io/v1/namespaces/nrr-netpol-test/leases/ba65f13e.readiness.node.x-k8s.io?timeout=5s\": context deadline exceeded"
Added 6443 through networkPolicy.egress, and it recovered right away. It took the lease, started both controllers, and reconciled all nodes, with no pod restart.

Note that the pod showed 1/1 Ready the whole time despite the readiness check failing which is normal behaviour

Suggestions:

Allow both 443 and 6443 by default, or make the API server ports a value, something like networkPolicy.apiServerPorts: [443, 6443]. I think the value is better, so people can match whatever their API server uses.

Also please update the unit test. Right now it only checks for 443.

Adds a networkPolicy section to values.yaml that templates into a
NetworkPolicy resource, disabled by default. When enabled it allows
kubelet probes, the webhook and metrics ports when those servers are
on, plus configurable API server (defaulting to 443 and 6443 for
k3s/kubeadm compatibility) and DNS egress, with extra ingress/egress
rules appendable verbatim. Covered by helm-unittest like the other
templates.

Signed-off-by: Divyansh Rawat <divyanshrawatofficial@gmail.com>
@DsThakurRawat
DsThakurRawat force-pushed the fix/480-network-policy branch from d35d92d to d2646aa Compare October 19, 2026 16:16
@DsThakurRawat

Copy link
Copy Markdown
Contributor Author

Good catch @sairamreddybhavanam, thanks for verifying on k3s with Calico.

Added networkPolicy.apiServerPorts: [443, 6443] to values.yaml and updated the template to iterate over them, allowing both 443 and 6443 by default while letting operators customize the list to match their cluster API server port. Also updated the helm-unittest suite to assert both default ports and verify custom port overrides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add optional NetworkPolicy to the Helm chart

2 participants