liveBook · Manning

Kubectl edit

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

kubectl edit is a kubectl command that opens a Kubernetes resource for interactive modification and submits the changed configuration.

kubectl edit opens a live Kubernetes resource in Vim, allowing an administrator to change its YAML configuration and submit the update directly to the cluster. section 6.4.3 section 8.1

Use it for focused operational changes when the resource already exists:

  • Change a Service from ClusterIP to LoadBalancer by editing its type, then verify the assigned external IP with kubectl get svc. section 6.4.3
  • Repair a failing Deployment by adding a required environment variable, save with :wq, and verify recovery with kubectl get po. section 8.1
  • Correct a Service port when requests fail, then retry the request and inspect selectors and pod labels if connectivity remains broken. section 8.3.2

Fixing a Service port

Run kubectl edit svc nginx-svc, change the exposed port from 3306 to 80 in Vim, press Esc, type :wq, and retry curl -k http://10.96.119.24. A successful response returns the nginx welcome page. section 8.3.2

root@kind-control-plane:/# kubectl edit svc nginx-svc
service/nginx-svc edited 
root@kind-control-plane:/# curl -k http://10.96.119.24
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http:/ /nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http:/ /nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

Shows the edit command followed by a successful request, making the edit-and-verify workflow directly inspectable. section 8.3.2

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Explains the edit-save-verify workflow with Vim and operational outcomes, but does not descend into API-server or controller internals.
Examples
Demonstrates LoadBalancer conversion, MySQL password repair, and nginx Service-port correction followed by command-based verification.
What it assumes
Assumes kubectl and basic YAML familiarity, while noting that fresh environments may require installing Vim before editing.
What you can do after
Operate/configure existing Kubernetes resources interactively and verify changes through service output, pod status, or application requests.
How it connects
Connects interactive editing with Kubernetes Services, Deployments, Pods, YAML, labels, selectors, ports, and environment variables.

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 Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.