Course contentsShow
← Cloud and Infrastructure
Lesson 1137 of 2,98922. Kubernetes ArchitectureFree lesson

Editing Resources with kubectl edit

Using kubectl edit to modify live resources directly in your default editor.

Editing Resources with kubectl edit

What You'll Learn

You'll learn how to modify live Kubernetes resources directly in your terminal using kubectl edit, a quick way to make changes without managing separate YAML files.

Why Edit Resources Directly?

Think of kubectl edit as opening a document in your word processor—you see the current content, make your changes, save, and close. Instead of deleting a resource and recreating it (or keeping a separate YAML file), you can edit what's already running in your cluster.

When you run kubectl edit, Kubernetes fetches the resource's current definition, opens it in your default editor (usually vi or nano), and waits for you to make changes. When you save and exit, kubectl validates and applies your modifications automatically.

How It Works

The basic syntax follows the pattern you've learned with get and describe:

kubectl edit deployment my-app
kubectl edit service my-service
kubectl edit pod my-pod -n production

Your editor opens with the resource's full YAML definition. You modify the fields you need—perhaps changing replica counts, updating an image version, or adjusting environment variables. Save and quit, and Kubernetes attempts to apply your changes immediately.

When to Use It

kubectl edit shines for quick fixes in development or troubleshooting scenarios—adjusting a configuration value, fixing a typo, or testing a small change. However, for production environments, using kubectl apply with version-controlled YAML files is preferred because it maintains an audit trail and enables repeatable deployments.

Key Takeaway: kubectl edit opens live Kubernetes resources in your editor for direct modification—fast and convenient for quick changes, but declarative files with apply remain best practice for production workflows.