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

