Skip to content

Issue in kubectl autoscale dry-run output #1785

@wissemkadri

Description

@wissemkadri

What happened:
When I ran:

kubectl autoscale -n my-ns deployment my-workload \
  --min 1 --max 5 --cpu-percent 50 \
  --dry-run=client -o yaml

the generated manifest did not include the namespace field:

metadata:
  name: my-workload

What you expected to happen:

The generated YAML should include the metadata.namespace field to reflect the namespace provided in the command, e.g.:

metadata:
  name: my-workload
  namespace: my-ns

How to reproduce it (as minimally and precisely as possible):

  1. Create a namespace:
kubectl create namespace my-ns
  1. Create a deployment in that namespace:
kubectl create deployment my-workload --image=nginx -n my-ns
  1. Generate an HPA manifest with --dry-run=client:
kubectl autoscale -n my-ns deployment my-workload \
  --min 1 --max 5 --cpu-percent 50 \
  --dry-run=client -o yaml
  1. Inspect the output:
    The generated YAML does not include metadata.namespace, even though -n my-ns was explicitly specified.

Anything else we need to know?:
It happened while I was doing my CKA test. The exam environment uses kubectl version 1.33.

Environment:

  • Kubernetes client and server versions (use kubectl version): v1.34.1 - v1.34.1+k3s1
  • Cloud provider or hardware configuration: Local environment
  • OS (e.g: cat /etc/os-release): Ubuntu 24.04.2 LTS

Metadata

Metadata

Assignees

Labels

kind/bugCategorizes issue or PR as related to a bug.priority/backlogHigher priority than priority/awaiting-more-evidence.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions