Skip to content

feat: cache versioned kubelet kubectl package binaries#8287

Open
awesomenix wants to merge 1 commit intomainfrom
nishp/fastkubeletfrompkg
Open

feat: cache versioned kubelet kubectl package binaries#8287
awesomenix wants to merge 1 commit intomainfrom
nishp/fastkubeletfrompkg

Conversation

@awesomenix
Copy link
Copy Markdown
Contributor

What this does

This change avoids unnecessary kubelet/kubectl package installation work during CSE when the corresponding binaries are already
available on the VHD.

Today, Ubuntu and Mariner/Azure Linux cache the kubelet/kubectl PMC packages on the VHD, but CSE still installs them via the package
manager/runtime package flow. That has a few downsides:

  • it re-runs package installation logic during provisioning
  • on Ubuntu, dpkg -i triggers package postinst behavior for kubelet.service
  • we pay extra provisioning latency even though AKS already owns kubelet service configuration and startup

This PR changes the flow so VHD build materializes versioned kubelet/kubectl binaries from the cached package artifacts into:

  • /opt/bin/kubelet-<k8sVersion>
  • /opt/bin/kubectl-<k8sVersion>

Then, during CSE, if the requested version is already present in /opt/bin, we reuse the existing cache-first path and do the final
rename into place instead of reinstalling from the package.

Changes

VHD build

  • extend vhdbuilder/packer/install-dependencies.sh so cached kubelet/kubectl package artifacts also produce versioned binaries
    under /opt/bin
  • support both:
    • Ubuntu: extract /usr/bin/<tool> from cached .deb
    • Mariner/Azure Linux: extract /usr/bin/<tool> from cached .rpm

CSE

  • add a shared helper to detect whether versioned kubelet/kubectl binaries already exist in /opt/bin
  • update Ubuntu and Mariner package-based install paths to:
    • use the cached versioned binaries when available
    • fall back to existing package install behavior when the cache is not present
    • continue respecting SHOULD_ENFORCE_KUBE_PMC_INSTALL=true

Tests

  • add/extend coverage for the cache-first kubelet/kubectl flow
  • extend Linux VHD content validation to verify package-backed kubelet/kubectl versions also materialize versioned binaries in
    /opt/bin

Why

This keeps kubelet/kubectl aligned with the existing kubernetes-binaries flow:

  • cache versioned binaries on the image
  • do a cheap final move during provisioning

Expected benefits:

  • lower CSE latency
  • avoid unnecessary package-manager work during provisioning
  • avoid Ubuntu kubelet package postinst side effects when the VHD already has the requested binary

Notes

  • this does not remove the existing package fallback path
  • if the versioned binary is missing, CSE still falls back to the current package installation behavior
  • SHOULD_ENFORCE_KUBE_PMC_INSTALL=true still forces the package path for validation / test scenarios

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes Linux node provisioning by reusing kubelet/kubectl binaries already cached on the VHD (materialized as versioned files under /opt/bin) instead of reinstalling via the package manager during CSE.

Changes:

  • VHD build: extract kubelet/kubectl binaries from cached .deb/.rpm artifacts into /opt/bin/<tool>-<k8sVersion>.
  • CSE: add shared helpers to detect/move cached versioned kube binaries; update Ubuntu and Mariner package-based kubelet/kubectl install paths to prefer cache unless SHOULD_ENFORCE_KUBE_PMC_INSTALL=true.
  • Tests: extend VHD content validation and add/extend ShellSpec coverage for the cache-first behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
vhdbuilder/packer/install-dependencies.sh Adds VHD-build extraction of kubelet/kubectl binaries from cached package artifacts into versioned /opt/bin paths.
vhdbuilder/packer/test/linux-vhd-content-test.sh Extends VHD content tests to validate versioned package-backed kubelet/kubectl binaries exist and match expected versions.
parts/linux/cloud-init/artifacts/cse_install.sh Adds shared helpers to detect and move cached versioned kubelet/kubectl binaries; reuses them in the URL-based install flow.
parts/linux/cloud-init/artifacts/ubuntu/cse_install_ubuntu.sh Updates Ubuntu package-based kubelet/kubectl install path to prefer cached versioned binaries.
parts/linux/cloud-init/artifacts/mariner/cse_install_mariner.sh Updates Mariner/AzureLinux package-based kubelet/kubectl install path to prefer cached versioned binaries.
spec/parts/linux/cloud-init/artifacts/cse_install_ubuntu_spec.sh Adds ShellSpec coverage for Ubuntu cache-first kubelet/kubectl install behavior.
spec/parts/linux/cloud-init/artifacts/cse_install_mariner_spec.sh Adds ShellSpec coverage for Mariner cache-first kubelet/kubectl install behavior.

@awesomenix awesomenix force-pushed the nishp/fastkubeletfrompkg branch from 98894d6 to 9614c74 Compare April 12, 2026 15:27
@awesomenix awesomenix changed the title Cache versioned kubelet kubectl package binaries feat: cache versioned kubelet kubectl package binaries Apr 12, 2026
Copilot AI review requested due to automatic review settings April 12, 2026 15:34
@awesomenix awesomenix force-pushed the nishp/fastkubeletfrompkg branch from 9614c74 to edbcee6 Compare April 12, 2026 15:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

@awesomenix awesomenix force-pushed the nishp/fastkubeletfrompkg branch from edbcee6 to b1dd3e8 Compare April 12, 2026 17:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment on lines +52 to +56
echo "Unpacking usr/bin/${packageName} from ${downloadDir}/${packageName}-${desiredVersion}*"
mkdir -p "$(dirname "${targetPath}")"
# This assumes that the binary will either be in /usr/bin or /usr/local/bin, but not both.
rpm2cpio "${rpmFile}" | cpio -i --to-stdout "./usr/bin/${rpmBinaryName}" "./usr/local/bin/${rpmBinaryName}" | install -m0755 /dev/stdin "${targetBinDir}/${targetBinaryName}"
rm -rf ${downloadDir}
rpm2cpio "${rpmFile}" | cpio -i --to-stdout "./usr/bin/${packageName}" "./usr/local/bin/${packageName}" | install -m0755 /dev/stdin "${targetPath}"
rm -rf "${downloadDir}"
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

This rpm2cpio | cpio -i --to-stdout call requests both ./usr/bin/<name> and ./usr/local/bin/<name> at once. If the RPM contains only one of these, cpio can fail (and if both exist it may concatenate both files to stdout), leading to an empty/corrupted binary being installed. Please extract exactly one resolved path (e.g., inspect the RPM file list first, or try /usr/bin/... and fall back to /usr/local/bin/... only if needed).

Copilot uses AI. Check for mistakes.

local sourceBinary="${extractDir}/usr/bin/${packageName}"
if [ ! -f "${sourceBinary}" ]; then
echo "Failed to locate usr/bin/${packageName} in ${debFile}"
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

Minor: the error message says usr/bin/${packageName} but the intended path is /usr/bin/${packageName} (leading slash missing). Fixing this makes failures clearer when a .deb doesn’t contain the expected binary path.

Suggested change
echo "Failed to locate usr/bin/${packageName} in ${debFile}"
echo "Failed to locate /usr/bin/${packageName} in ${debFile}"

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.

2 participants