From eeee75e1d02d2148972e3862ac8bc59c3a08daca Mon Sep 17 00:00:00 2001 From: ogormans-deptstack Date: Sat, 27 Sep 2025 07:53:48 +0000 Subject: [PATCH] KEP 34146 --- .../34146-kubectl-explain-example/README.md | 628 ++++++++++++++++++ .../34146-kubectl-explain-example/kep.yaml | 21 + 2 files changed, 649 insertions(+) create mode 100644 keps/sig-cli/34146-kubectl-explain-example/README.md create mode 100644 keps/sig-cli/34146-kubectl-explain-example/kep.yaml diff --git a/keps/sig-cli/34146-kubectl-explain-example/README.md b/keps/sig-cli/34146-kubectl-explain-example/README.md new file mode 100644 index 00000000000..df8c0f93c31 --- /dev/null +++ b/keps/sig-cli/34146-kubectl-explain-example/README.md @@ -0,0 +1,628 @@ + +# KEP-34146: kubectl example - kubectl explain example: practical output that can be applied | trialed by new user to advanced + + + + + + +- [Release Signoff Checklist](#release-signoff-checklist) +- [Summary](#summary) +- [Motivation](#motivation) + - [Goals](#goals) + - [Non-Goals](#non-goals) +- [Proposal](#proposal) + - [Basic Usage](#basic-usage) + - [Risks and Mitigations](#risks-and-mitigations) +- [Design Details](#design-details) + - [Test Plan](#test-plan) + - [Prerequisite testing updates](#prerequisite-testing-updates) + - [Unit tests](#unit-tests) + - [Integration tests](#integration-tests) + - [e2e tests](#e2e-tests) + - [Graduation Criteria](#graduation-criteria) + - [Alpha](#alpha) + - [Beta](#beta) + - [GA](#ga) + - [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) +- [Future Work](#future-work) + + +## 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) + - [ ] e2e Tests for all Beta API Operations (endpoints) + - [ ] (R) Ensure GA e2e tests meet requirements for [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md) + - [ ] (R) Minimum Two Week Window for GA e2e tests to prove flake free +- [ ] (R) Graduation criteria is in place + - [ ] (R) [all GA Endpoints](https://github.com/kubernetes/community/pull/1806) must be hit by [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md) +- [ ] (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 + + + +[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 adding a new kubectl subcommand `kubectl example` that provides generic seed YAML for different resources, complementing the existing `kubectl explain` command. Think of it as `curl cht.sh/kubectl` but distributed at the CLI level. + +The idea is to provide a `kubectl explain` then `kubectl example` flow, where users can get detailed explanations and then practical YAML examples. + +## Motivation + +Users often need practical, applicable YAML examples for Kubernetes resources. While `kubectl explain` provides detailed schema information, it doesn't give users ready-to-use YAML snippets. This creates a gap where users must manually construct YAML from documentation, which can be error-prone and time-consuming, especially for beginners. + +This KEP addresses that gap by introducing `kubectl example`, which outputs generic seed YAML for resources. The examples are designed to be: + +- **Immediately applicable**: Can be piped directly to `kubectl apply` for testing. +- **Best-practice oriented**: Include common configurations like resource limits, labels, and annotations. +- **Educational**: Serve as templates that users can modify for their needs. +- **Comprehensive**: Cover a wide range of Kubernetes resources. + +For instance: + +- `kubectl explain pod` -- detailed explanation of resource + +- `kubectl example pod` -- generic YAML output for a standard pod with linux - alpine image + +This enhances the user experience, especially for new users learning Kubernetes, by providing immediate practical output that can be applied or trialed. + +Additionally, this could socialize further the use of `kubectl get --raw` on APIs and potentially automate ingestion of that to explain what the API controls in flight within a cluster at a version. + +### Goals + +1. Provide a new `kubectl example` subcommand that outputs generic seed YAML for Kubernetes resources. +2. Complement `kubectl explain` by offering practical, applicable examples. +3. Support common resources with sensible defaults. +4. Potentially integrate with `kubectl get --raw` to enhance API understanding. + +### Non-Goals + +1. Replace or modify `kubectl explain`. +2. Provide exhaustive examples for all possible configurations. +3. Generate examples dynamically from cluster state. + + +## Proposal + +### Basic Usage + +The following user experience should be possible with `kubectl example`: + +```shell +kubectl example pod +``` + +This would output a generic YAML for a Pod resource, e.g.: + +```yaml +apiVersion: v1 +kind: Pod +metadata: + name: example-pod +spec: + containers: + - name: example-container + image: alpine:latest + command: ["sleep", "3600"] + resources: + requests: + memory: "64Mi" + cpu: "250m" + limits: + memory: "128Mi" + cpu: "500m" +``` + +For a PersistentVolumeClaim: + +```yaml +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: example-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +``` + +Similarly for other resources like deployments, services, etc. + +### Advanced Usage + +- `kubectl example deployment --replicas=3` - Generate example with custom parameters +- `kubectl example --list` - List all available example resources +- `kubectl example pod | kubectl apply -f -` - Apply the example directly + +### Risks and Mitigations + +#### No Examples Available for a Resource + +##### Risk + +The requested resource does not have a predefined example. + +##### Mitigation + +Return an error message suggesting to use `kubectl explain` for schema information or check available examples with `kubectl example --list`. + +#### Outdated Examples + +##### Risk + +Examples may not reflect the latest best practices or API changes. + +##### Mitigation + +Examples will be maintained as part of kubectl releases, with community contributions encouraged. Version-specific examples can be added if needed. + + +## Design Details + +The new `kubectl example` command will be implemented as a new subcommand in kubectl, similar to `kubectl explain`. + +High-level Approach: + +1. User types `kubectl example ` +2. kubectl resolves the resource type using discovery (similar to `kubectl explain`) +3. kubectl looks up a predefined YAML template for that resource +4. kubectl outputs the YAML to stdout + +Templates will be hardcoded in the kubectl binary for common resources like pods, deployments, services, etc. Examples should use sensible defaults, such as alpine images for containers. + +For extensibility, future versions could allow loading examples from files or online repositories, but initially, examples will be built-in. + +### Example Storage and Management + +Examples will be stored as Go string literals or embedded files in the kubectl codebase. Each example will include: + +- Valid YAML structure +- Sensible default values +- Comments explaining key sections +- Resource limits and requests where applicable +- Common labels and annotations + +### Adding New Examples + +To add a new example: + +1. Create the YAML template +2. Add it to the examples map in the code +3. Update tests +4. Update documentation + +### Parameterization + +Future enhancements could support basic parameterization, such as custom names, replica counts, or image versions, using Go templates or simple string replacement. + +### Test Plan + +##### Prerequisite testing updates + +None required. + +##### Unit tests + +Unit tests will verify that the correct YAML is output for supported resources and appropriate errors for unsupported ones. + +##### Integration tests + +Integration tests will ensure the command integrates well with kubectl's existing infrastructure, such as resource discovery. + +##### e2e tests + +E2E tests will validate that the output YAML can be applied to a cluster (e.g., `kubectl example pod | kubectl apply -f -` creates a running pod). + +### Graduation Criteria + +#### Alpha + +- Basic `kubectl example` command implemented with examples for core resources (pod, deployment, service). +- Unit and integration tests in place. + +#### Beta + +- Expanded set of examples for more resources. +- User feedback incorporated. +- E2E tests passing. + +#### GA + +- Comprehensive examples for commonly used resources. +- Documentation updated. +- No breaking changes. + +### Upgrade / Downgrade Strategy + +N/A - This is a new command, no upgrades needed. + +### Version Skew Strategy + +The command relies on kubectl's resource discovery, which should work across versions. Examples are static, so no skew issues. + +### Test Plan + + + +[x] I/we understand the owners of the involved components may require updates to +existing tests to make this code solid enough prior to committing the changes necessary +to implement this enhancement. + +##### Prerequisite testing updates + + + +##### Unit tests + +Unit tests will verify that the correct YAML is output for supported resources, appropriate errors for unsupported ones, and that the YAML is valid. + +##### Integration tests + +Integration tests will ensure the command integrates well with kubectl's existing infrastructure, such as resource discovery, and that examples are consistent with cluster capabilities. + +##### e2e tests + +E2E tests will validate that the output YAML can be applied to a cluster successfully (e.g., `kubectl example pod | kubectl apply -f -` creates a running pod), and that examples work across different cluster configurations. + +### Graduation Criteria + +#### Alpha + +- Basic `kubectl example` command implemented with examples for core resources (pod, deployment, service, persistentvolumeclaim). +- Unit and integration tests in place. +- Command available in kubectl builds. + +#### Beta + +- Expanded set of examples for more resources (configmap, secret, job, etc.). +- User feedback incorporated from alpha usage. +- E2E tests passing in CI. +- Documentation updated with examples. + +#### GA + +- Comprehensive examples for commonly used resources. +- Examples validated against multiple Kubernetes versions. +- No breaking changes in output format. +- Feature promoted as stable in kubectl documentation. + + + +### Upgrade / Downgrade Strategy + + + +N/A + +### Version Skew Strategy + +The command relies on kubectl's resource discovery, which should work across versions. Examples are static YAML templates, so no version skew issues with the output itself. However, the applicability of examples may vary based on cluster capabilities (e.g., newer API versions). The command will use the latest available API versions for resource discovery. + +## Production Readiness Review Questionnaire + + + +### Feature Enablement and Rollback + +###### How can this feature be enabled / disabled in a live cluster? + +- [x] Other + - Describe the mechanism: This is a new kubectl subcommand. It is enabled by building kubectl with the new code. No feature gate. + - Will enabling / disabling the feature require downtime of the control plane? No + - Will enabling / disabling the feature require downtime or reprovisioning of a node? No + +###### Does enabling the feature change any default behavior? + +No, it's a new command. + +###### Can the feature be disabled once it has been enabled (i.e. can we roll back the enablement)? + +Yes, by using an older version of kubectl without the command. + +###### What happens if we reenable the feature if it was previously rolled back? + +Normal operation. + +###### Are there any tests for feature enablement/disablement? + +Unit tests for the command presence. + + +### Rollout, Upgrade and Rollback Planning + +###### How can a rollout or rollback fail? Can it impact already running workloads? + +No, this is a new CLI command. No impact on workloads. + +###### What specific metrics should inform a rollback? + +N/A + +###### Were upgrade and rollback tested? Was the upgrade->downgrade->upgrade path tested? + +N/A + +###### 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 + +###### How can someone using this feature know that it is working for their instance? + +Run `kubectl example pod` and verify YAML output. + +###### What are the reasonable SLOs (Service Level Objectives) for the enhancement? + +N/A + +###### What are the SLIs (Service Level Indicators) an operator can use to determine the health of the service? + +- [x] Other (treat as last resort) + - Details: N/A + +###### Are there any missing metrics that would be useful to have to improve observability of this feature? + +N/A + +### Dependencies + +None + +### Scalability + +###### Will enabling / using this feature result in any new API calls? + +Potentially, also happy to make it a subcommand of explain if that's logically neater: +``` +kubectl explain example pod +``` + +###### 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. + +###### Can enabling / using this feature result in resource exhaustion of some node resources (PIDs, sockets, inodes, etc.)? + +No. + +### Troubleshooting + +###### How does this feature react if the API server and/or etcd is unavailable? + +The command doesn't require API server access, as examples are static. diff --git a/keps/sig-cli/34146-kubectl-explain-example/kep.yaml b/keps/sig-cli/34146-kubectl-explain-example/kep.yaml new file mode 100644 index 00000000000..d5bb3b5dd3e --- /dev/null +++ b/keps/sig-cli/34146-kubectl-explain-example/kep.yaml @@ -0,0 +1,21 @@ +id: "34146" +name: kubectl-example +title: kubectl example - kubectl explain but immediate practical output that can be applied | trialed by new user to advanced +kep-number: 34146 +authors: ['@ogormans-deptstack'] +owning-sig: sig-cli +participating-sigs: [sig-cli] +reviewers: [] +approvers: [] +creation-date: "2025-09-27" +last-updated: "2025-09-27" +status: provisional +stage: alpha +latest-milestone: "v1.35" +milestone: + alpha: "v1.35" + beta: "v1.36" + stable: "v1.37" +feature-gates: [] +disable-supported: false +metrics: [] \ No newline at end of file