liveBook · Manning

Kubectl edit

As explained in Kubernetes in Action, Second Edition

kubectl edit is a Kubernetes command that interactively modifies a Kubernetes object definition through the Kubernetes API.

kubectl edit interactively modifies a Kubernetes object definition through the Kubernetes API. It is useful when an existing object needs a targeted change without first editing a local manifest. section 7.2.2

Use kubectl edit when you need to:

  • Add or change labels directly on an existing object, although kubectl label is simpler for label-only changes. section 7.2.2
  • Change a Service field while preserving related settings, such as changing port from 8080 to 80 while leaving targetPort at 8080. section 11.1.2
  • Choose between direct API editing and updating a manifest followed by kubectl apply. section 7.2.2 section 11.1.2

Change a Service port

Run `kubectl edit svc quiz`, change the Service's `port` from `8080` to `80`, and leave `targetPort: 8080` unchanged because the quiz Pod listens on that port. The Service then exposes port 80 while forwarding to port 8080. section 11.1.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Demonstrates targeted field changes and contrasts direct editing with manifest reapplication, without detailing editor behavior or API internals.
Examples
Demonstrates editing a quiz Service port and directly modifying labels on existing Pods.
What you can do after
Operate existing Kubernetes objects with kubectl by applying precise interactive changes to their definitions.
How it connects
Connects Kubernetes objects, the Kubernetes API, manifests, kubectl apply, labels, Pods, and Services.

Also explained in

Compare how 2 books explain kubectl edit →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.