Nikhita Raghunath
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # KEP-2590: Kubectl Subresource Support <!-- toc --> - [Release Signoff Checklist](#release-signoff-checklist) - [Summary](#summary) - [Motivation](#motivation) - [Goals](#goals) - [Non-Goals](#non-goals) - [Proposal](#proposal) - [User Stories (Optional)](#user-stories-optional) - [Story 1](#story-1) - [Story 2](#story-2) - [Notes/Constraints/Caveats (Optional)](#notesconstraintscaveats-optional) - [Risks and Mitigations](#risks-and-mitigations) - [Design Details](#design-details) - [Test Plan](#test-plan) - [Graduation Criteria](#graduation-criteria) - [Upgrade / Downgrade Strategy](#upgrade--downgrade-strategy) - [Version Skew Strategy](#version-skew-strategy) - [Production Readiness Review Questionnaire](#production-readiness-review-questionnaire) - [Feature Enablement and Rollback](#feature-enablement-and-rollback) - [Rollout, Upgrade and Rollback Planning](#rollout-upgrade-and-rollback-planning) - [Monitoring Requirements](#monitoring-requirements) - [Dependencies](#dependencies) - [Scalability](#scalability) - [Troubleshooting](#troubleshooting) - [Implementation History](#implementation-history) - [Drawbacks](#drawbacks) - [Alternatives](#alternatives) - [Infrastructure Needed (Optional)](#infrastructure-needed-optional) <!-- /toc --> ## Release Signoff Checklist Items marked with (R) are required *prior to targeting to a milestone / release*. - [ ] (R) Enhancement issue in release milestone, which links to KEP dir in [kubernetes/enhancements] (not the initial KEP PR) - [ ] (R) KEP approvers have approved the KEP status as `implementable` - [ ] (R) Design details are appropriately documented - [ ] (R) Test plan is in place, giving consideration to SIG Architecture and SIG Testing input (including test refactors) - [ ] (R) Graduation criteria is in place - [ ] (R) Production readiness review completed - [ ] (R) Production readiness review approved - [ ] "Implementation History" section is up-to-date for milestone - [ ] User-facing documentation has been created in [kubernetes/website], for publication to [kubernetes.io] - [ ] Supporting documentation—e.g., additional design documents, links to mailing list discussions/SIG meetings, relevant PRs/issues, release notes <!-- **Note:** This checklist is iterative and should be reviewed and updated every time this enhancement is being considered for a milestone. --> [kubernetes.io]: https://kubernetes.io/ [kubernetes/enhancements]: https://git.k8s.io/enhancements [kubernetes/kubernetes]: https://git.k8s.io/kubernetes [kubernetes/website]: https://git.k8s.io/website ## Summary This KEP proposes supporting a new flag `--subresource` to get, apply, patch, edit and replace kubectl commands to fetch and update `status` and `scale` subresources. ## Motivation Today while testing or debugging, fetching subresources (like status) of API objects via kubectl involves using `kubectl --raw`. Patching subresources using kubectl is not possible at all and requires using curl directly. This method is very cumbersome and not user-friendly. This KEP adds subresources as a first class option in kubectl to allow users to work with the API in a generic fashion. ### Goals - Add a new flag `--subresource=[subresource-name]` to get, apply, patch, edit and replace kubectl commands to allow fetching and updating `status` and `scale` subresources for all resources (built-in and CRs) that support these subresources. - Display pretty printed table columns for the status (uses same columns as the main resource) and scale subresources. ### Non-Goals - Support subresources other than `status` and `scale`. - Allow updates to the status subresource if a controller is running against the main resource that reconciles `.status` part of the resource. - Allow specifying `additionalPrinterColumns` for CRDs for the status subresource. ## Proposal kubectl commands like get, apply, patch, edit and replace will now contain a new flag `--subresource=[subresource-name]` which will allow fetching and updating `status` and `scale` subresources for all API resources. When the `--subresource=status` flag is used against built-in API types, the `.status` field of the resource is _not_ updated since the built-in controllers run against the resource and reconcile the `.status` part. This also holds true for custom resources if a custom controller reconciles the `.status` part of the CR. It ensures that `.status` of built-in API types will never store arbitrary data. If `--subresource` flag is used for a resource that doesn't support the subresource, a `NotFound` error will be returned. ### Examples #### get ```shell= # for built-in types $ kubectl get deployment nginx-deployment --subresource=status NAME READY UP-TO-DATE AVAILABLE AGE nginx-deployment 3/3 3 3 43s $ kubectl get deployment nginx-deployment --subresource=scale NAME DESIREDREPLICAS AVAILABLEREPLICAS nginx-deployment 3 3 # for CRDS $ kubectl get crontab cron--subresource=status NAME SPEC REPLICAS AGE cron * * * * */5 3 4m52s $ kubectl get vmset vmset-1 --subresource=scale NAME DESIREDREPLICAS AVAILABLEREPLICAS cron 3 0 ``` Invalid subresources: ```shell= $ kubectl get pod nginx-deployment-66b6c48dd5-dv6gl --subresource=logs error: --subresource must be one of [status scale], not "logs" $ kubectl get pod nginx-deployment-66b6c48dd5-dv6gl --subresource=scale Error from server (NotFound): the server could not find the requested resource ``` #### patch ```shell= # For built-in types # update spec.replicas through scale subresource $ kubectl patch deployment nginx-deployment --subresource='scale' --type='merge' -p '{"spec":{"replicas":2}}' scale.autoscaling/nginx-deployment patched # spec.replicas is updated for the main resource $ k get deploy nginx-deployment NAME READY UP-TO-DATE AVAILABLE AGE nginx-deployment 2/2 2 2 4m # For CRDs $ kubectl patch crontabs cron --subresource='status' --type='merge' -p '{"status":{"replicas":2}}' crontab.stable.example.com/cron patched $ kubectl get crontab cron --subresource=scale NAME DESIREDREPLICAS AVAILABLEREPLICAS cron 3 2 ``` #### apply ```shell= # cron-with-status.yaml has .status.replicas=3 $ kubectl apply -f cron-with-status.yaml --subresource=status # .status.replicas is updated to 3 $ kubectl get crontabs cron -o jsonpath='{.status.replicas}' 3 # cron-with-status.yaml updated to include .status.replicas=2 # but is not applied if --subresource flag is not used $ kubectl apply -f cron-with-status.yaml # .status.replicas is not updated $ kubectl get crontabs cron -o jsonpath='{.status.replicas}' 3 ``` ### Notes While this flag now allows updating `.status` for custom resources when a custom controller is not running against them, this is _not_ problematic because: - This feature is gated by the `--subresource` flag, and does not change the default behavior for kubectl. - Updating `.status` is also possible today by using `curl` directly. ## Design Details ### Subresource support A new field `Subresource` and method `Subresource`/`WithSubresource` is added to the [builder], [helper] and [visitor] code to use the API object at the subresource path. [builder]: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/cli-runtime/pkg/resource/builder.go [helper]: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/cli-runtime/pkg/resource/helper.go [visitor]: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/cli-runtime/pkg/resource/visitor.go For each relevant kubectl command, a new flag `--subresource` is added. If the flag is specified, the value is also validated to ensure that it is a valid subresource. If the subresource does not exist for an API resource, a `NotFound` error is returned. ### Table printer To support table view for subresources using kubectl get, table convertor support is added to the the scale and status subresoruces for built-in and CRD types. For built-in types, `StatusStore` and `ScaleStore` are updated to implement the `TableConvertor` interface. `StatusStore` uses the same columns as the main resource object. The following column definitions for the `Scale` object are added to [printers.go] to support the scale subresource: - `Available Replicas` uses the json path `.status.replicas` of autoscalingv1.Scale object - `Desired Replicas` uses the json path of `.spec.replicas` of autoscalingv1.Scale object For custom resources: - the status subresoruce uses `additionalPrinterColumns` defined in the CRD. - the scale subresource follows the same column definitions as the built-in types, and are defined in [helpers.go]. [printers.go]: https://github.com/kubernetes/kubernetes/blob/master/pkg/printers/internalversion/printers.go#L88 [helpers.go]: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/helpers.go ### Test Plan - Unit tests, integration and e2e tests will be added. TODO: add in the POC and add more details here. ### Upgrade / Downgrade Strategy This functionality is contained entirely within kubectl and shares its strategy. No configuration changes are required. ### Version Skew Strategy Not applicable. There is nothing required of the API Server, so there can be no version skew. ## Production Readiness Review Questionnaire ### Feature Enablement and Rollback ###### How can this feature be enabled / disabled in a live cluster? <!-- Pick one of these and delete the rest. --> - [ ] Feature gate (also fill in values in `kep.yaml`) - Feature gate name: - Components depending on the feature gate: - [x] Other - Describe the mechanism: A new flag for kubectl commands - Will enabling / disabling the feature require downtime of the control plane? No, disabling the feature would be a client behaviour. - Will enabling / disabling the feature require downtime or reprovisioning of a node? (Do not assume `Dynamic Kubelet Config` feature is enabled). No, disabling the feature would be a client behaviour. ###### Does enabling the feature change any default behavior? While the feature now updates kubectl's behavior to allow updating subresources, it is gated by the `--subresource` flag so it does not change kubectl's default behavior. Subresources can also be updated using curl today so this feature only provides a consistent way to use the API via kubectl, but does not allow additional changes to the API that are not possible today. ###### Can the feature be disabled once it has been enabled (i.e. can we roll back the enablement)? Yes, rolling back to a previous version of `kubectl` will remove support for the `--subresource` flag and the ability to update subresources via kubectl. However, this does not "lock" us to any changes to the subresources that were made when the feature was enabled i.e. it does not remove the ability to update subresources for existing API resources completely. If a subresource of an exisiting API resource needs to be updated, this can be done via curl. ###### What happens if we reenable the feature if it was previously rolled back? The `--subresource` flag can be used and subresources can be updated via kubectl again. ###### Are there any tests for feature enablement/disablement? No, because it cannot be disabled or enabled in a single release. ### Rollout, Upgrade and Rollback Planning <!-- This section must be completed when targeting beta to a release. --> ###### How can a rollout fail? Can it impact already running workloads? The feature is encapsulated entirely within the kubectl binary, so rollout is an atomic client binary update. Subresources can always be updated via curl, so there are no version dependencies. ###### What specific metrics should inform a rollback? N/A ###### Were upgrade and rollback tested? Was the upgrade->downgrade->upgrade path tested? TODO: Describe manual testing that was done and the outcomes. <!-- Describe manual testing that was done and the outcomes. Longer term, we may want to require automated upgrade/rollback tests, but we are missing a bunch of machinery and tooling and can't do that now. --> ###### Is the rollout accompanied by any deprecations and/or removals of features, APIs, fields of API types, flags, etc.? No. ### Monitoring Requirements ###### How can an operator determine if the feature is in use by workloads? N/A ###### What are the SLIs (Service Level Indicators) an operator can use to determine the health of the service? N/A ###### What are the reasonable SLOs (Service Level Objectives) for the above SLIs? N/A ###### Are there any missing metrics that would be useful to have to improve observability of this feature? N/A ### Dependencies ###### Does this feature depend on any specific services running in the cluster? No ### Scalability ###### Will enabling / using this feature result in any new API calls? - API call type (e.g. PATCH pods): GET, PATCH, PUT `/<subresource>` - Estimated throughput: Negligible, because it's human initiated. At maximum, each command would involve two calls: 1 read and 1 mutate. - Originating component(s): kubectl ###### Will enabling / using this feature result in introducing new API types? No ###### Will enabling / using this feature result in any new calls to the cloud provider? No ###### Will enabling / using this feature result in increasing size or count of the existing API objects? No ###### Will enabling / using this feature result in increasing time taken by any operations covered by existing SLIs/SLOs? No ###### Will enabling / using this feature result in non-negligible increase of resource usage (CPU, RAM, disk, IO, ...) in any components? No ### Troubleshooting ###### How does this feature react if the API server and/or etcd is unavailable? `kubectl` is not resilient to API server unavailability. ###### What are other known failure modes? N/A ###### What steps should be taken if SLOs are not being met to determine the problem? N/A ## Implementation History 2021-03-01: Initial [POC PR] created 2021-04-xx: KEP proposed [POC PR]: https://github.com/kubernetes/kubernetes/pull/99556

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully