Skip to content

feat(k8s): support multi-container (sidecar) SkyPilot pods#8444

Merged
aylei merged 13 commits into
skypilot-org:masterfrom
php-workx:upstream/k8s-multi-container-pods
Jan 24, 2026
Merged

feat(k8s): support multi-container (sidecar) SkyPilot pods#8444
aylei merged 13 commits into
skypilot-org:masterfrom
php-workx:upstream/k8s-multi-container-pods

Conversation

@php-workx

@php-workx php-workx commented Dec 27, 2025

Copy link
Copy Markdown
Contributor

SkyPilot’s Kubernetes provisioning and control-plane interactions currently assume SkyPilot pods contain a single container and implicitly target containers[0]. In real clusters, mutating webhooks often inject sidecars (log shippers, mesh proxies, security agents), which breaks this assumption and can cause provisioning failures or commands executing in the wrong container.

This PR adds multi-container awareness by consistently targeting the primary workload container (default: ray-node) when executing commands or inspecting resources.

Key changes

  • Select the primary container explicitly instead of assuming the first container is the workload container.
  • Wire container selection through Kubernetes command execution, so kubectl exec targets the intended container when sidecars are present.
  • Centralize the default workload container name (ray-node) as a constant: sky/provision/kubernetes/constants.py:RAY_NODE_CONTAINER_NAME.

Behavior

  • Existing single-container pods continue to work unchanged.
  • When sidecars are injected, SkyPilot continues to exec into the workload container, preventing provisioning/runtime regressions.

Tested (run the relevant ones):

  • Code formatting: install pre-commit (auto-check on commit) or bash format.sh
  • Any manual or new tests for this PR (please specify below)
  • All smoke tests: /smoke-test (CI) or pytest tests/test_smoke.py (local)
  • Relevant individual tests: /smoke-test -k test_name (CI) or pytest tests/test_smoke.py::test_name (local)
  • Backward compatibility: /quicktest-core (CI) or pytest tests/smoke_tests/test_backward_compat.py (local)

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @php-workx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances SkyPilot's compatibility with Kubernetes environments that utilize multi-container pods, particularly those where sidecars are automatically injected. By introducing explicit targeting of the primary workload container, SkyPilot can now reliably execute commands and gather resource information, preventing operational disruptions and ensuring correct behavior in complex Kubernetes deployments. This change improves the robustness and flexibility of SkyPilot's Kubernetes provisioning capabilities without affecting existing single-container setups.

Highlights

  • Multi-Container Pod Support: SkyPilot now explicitly targets the primary workload container (defaulting to 'ray-node') within Kubernetes pods, addressing issues caused by sidecar injection from mutating webhooks.
  • Consistent Container Targeting: Command execution (kubectl exec) and resource inspection now consistently use the specified primary container, preventing commands from running in unintended sidecar containers.
  • Centralized Configuration: The default primary container name ('ray-node') has been centralized into a constant, RAY_NODE_CONTAINER_NAME, for easier management and consistency.
  • Improved Resource Parsing: Resource requests (CPU, memory, GPU) are now correctly parsed from the identified primary container, ensuring accurate resource allocation and monitoring.
  • Removed Single-Container Assumption: The previous assertion limiting deployments to a single container has been removed, allowing for more flexible pod configurations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces explicit targeting of the primary workload container, named 'ray-node', within Kubernetes pods to better support multi-container deployments. Changes include adding a RAY_NODE_CONTAINER_NAME constant, modifying KubernetesCommandRunner to accept a container argument for kubectl exec and rsync operations, and implementing a get_pod_primary_container utility function. This utility is used across the codebase to ensure pre-initialization, AppArmor annotation removal, resource parsing (CPU, memory, GPU), and command execution correctly interact with the intended container. The previous restriction of single-container deployments has been removed. A review comment suggests a more concise Pythonic approach for retrieving CPU requests using dictionary get with or operators.

Comment thread sky/provision/kubernetes/instance.py Outdated
@Michaelvll Michaelvll requested a review from aylei January 15, 2026 22:25
@aylei

aylei commented Jan 16, 2026

Copy link
Copy Markdown
Collaborator

/smoke-test

@aylei aylei left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding this @php-workx ! Could you include a smoke test with sidecar injected to make this PR self-contained?

Comment thread sky/provision/kubernetes/instance.py Outdated
@aylei

aylei commented Jan 23, 2026

Copy link
Copy Markdown
Collaborator

/smoke-test -k test_kubernetes_pod_config_sidecar

1 similar comment
@aylei

aylei commented Jan 23, 2026

Copy link
Copy Markdown
Collaborator

/smoke-test -k test_kubernetes_pod_config_sidecar

@aylei

aylei commented Jan 23, 2026

Copy link
Copy Markdown
Collaborator

/smoke-test -k test_kubernetes_pod_config_sidecar --kubernetes

1 similar comment
@aylei

aylei commented Jan 23, 2026

Copy link
Copy Markdown
Collaborator

/smoke-test -k test_kubernetes_pod_config_sidecar --kubernetes

@aylei aylei force-pushed the upstream/k8s-multi-container-pods branch 2 times, most recently from 33844cb to 441f613 Compare January 23, 2026 15:38
Signed-off-by: Aylei <rayingecho@gmail.com>
@aylei aylei force-pushed the upstream/k8s-multi-container-pods branch from 441f613 to 781ef64 Compare January 23, 2026 16:12
Signed-off-by: Aylei <rayingecho@gmail.com>
@aylei

aylei commented Jan 23, 2026

Copy link
Copy Markdown
Collaborator

/smoke-test -k test_kubernetes_pod_config_sidecar --kubernetes

@php-workx

Copy link
Copy Markdown
Contributor Author

Oh, seems like there was quite a bit of work left?! Thanks so much for pushing this forward, @aylei ! 🙏🏻

@aylei

aylei commented Jan 24, 2026

Copy link
Copy Markdown
Collaborator

/smoke-test --kubernetes

@aylei

aylei commented Jan 24, 2026

Copy link
Copy Markdown
Collaborator

/quicktest-core

@aylei aylei left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @php-workx !

@aylei aylei merged commit f0c38c4 into skypilot-org:master Jan 24, 2026
23 checks passed
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