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

[k8s] Optimize ingress creation to avoid nginx hot-reloads #3263

Merged
merged 4 commits into from
Mar 15, 2024

Conversation

romilbhardwaj
Copy link
Collaborator

@romilbhardwaj romilbhardwaj commented Mar 2, 2024

Each ingress rule creation triggers a hot reload of the nginx controller. Since previously SkyPilot generates the listed ingresses sequentially, this could lead to multiple reloads of the Nginx-Ingress-Controller within a brief period.

Consequently, the Nginx-Controller pod might spawn an excessive number of sub-processes. This surge triggers Kubernetes to kill and restart the Nginx due to the podPidsLimit parameter, which is typically set to a default value like 1024, and thus disrupts normal request handling.

This PR fixes this issue by batching ingress creation into one object containing multiple rules.

Tested (run the relevant ones):

  • Code formatting: bash format.sh
  • Tested: sky launch -c test --ports 8888-8899

Copy link
Collaborator

@Michaelvll Michaelvll left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this @romilbhardwaj! LGTM with two questions.

Comment on lines +77 to +83
content = network_utils.fill_ingress_template(
namespace=provider_config.get('namespace', 'default'),
service_details=service_details,
ingress_name=f'{cluster_name_on_cloud}-skypilot-ingress',
selector_key='skypilot-cluster',
selector_value=cluster_name_on_cloud,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we add the PR description in the comments here or some other places in the code for why we batch the rules? : )

Suggested change
content = network_utils.fill_ingress_template(
namespace=provider_config.get('namespace', 'default'),
service_details=service_details,
ingress_name=f'{cluster_name_on_cloud}-skypilot-ingress',
selector_key='skypilot-cluster',
selector_value=cluster_name_on_cloud,
)
content = network_utils.fill_ingress_template(
namespace=provider_config.get('namespace', 'default'),
service_details=service_details,
ingress_name=f'{cluster_name_on_cloud}-skypilot-ingress',
selector_key='skypilot-cluster',
selector_value=cluster_name_on_cloud,
)

Comment on lines +93 to +98
# Create or update the single ingress for all services
network_utils.create_or_replace_namespaced_ingress(
namespace=provider_config.get('namespace', 'default'),
ingress_name=f'{cluster_name_on_cloud}-skypilot-ingress',
ingress_spec=content['ingress_spec'],
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious, if we are changing the ingress for all the ports in batch, will this cause the other ports being unavailable for a while when a new port is added?

Also, just to confirm, when adding a new port, the original endpoint for the existing ports do not change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just curious, if we are changing the ingress for all the ports in batch, will this cause the other ports being unavailable for a while when a new port is added?

Yes, that's true. Nginx will do a hot reload whenever a new ingress rule is created. As a result, ports may be unavailable for a short duration before getting restotred.

Also, just to confirm, when adding a new port, the original endpoint for the existing ports do not change?

Yes, the original endpoint will remain the same, since the k8s service remains the same.

@romilbhardwaj romilbhardwaj merged commit 823999a into master Mar 15, 2024
19 checks passed
@romilbhardwaj romilbhardwaj deleted the k8s_ingress_optimization branch March 15, 2024 06:06
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.

2 participants