edit

Edit a resource

Edit a resource from the default editor.

The edit command allows you to directly edit any API resource you can retrieve via the command line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, or fall back to ‘vi’ for Linux or ‘notepad’ for Windows. You can edit multiple objects, although changes are applied one at a time. The command accepts filenames as well as command line arguments, although the files you point to must be previously saved versions of resources.

Editing is done with the API version used to fetch the resource. To edit using a specific API version, fully-qualify the resource, version, and group.

The default format is YAML. To edit in JSON, specify “-o json”.

Command

  1. $ kubectl edit (RESOURCE/NAME | -f FILENAME)

Example

Current State

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: nginx-dev
  5. labels:
  6. app: nginx
  7. spec:
  8. selector:
  9. matchLabels:
  10. app: nginx
  11. template:
  12. metadata:
  13. labels:
  14. app: nginx
  15. spec:
  16. containers:
  17. - name: nginx
  18. image: nginx:1.14.2
  1. $ kubectl get deployments
  2. NAME READY UP-TO-DATE AVAILABLE AGE
  3. nginx-dev 1/1 1 1 13m

Command

  1. $ kubectl edit deployment/nginx-dev

Edit

  1. kind: Deployment
  2. apiVersion: apps/v1
  3. metadata:
  4. name: nginx-dev
  5. namespace: default
  6. selfLink: /apis/apps/v1/namespaces/default/deployments/nginx-dev
  7. uid: 8799f7a6-e971-4285-bfac-0be1af6557d9
  8. resourceVersion: '2180'
  9. generation: 1
  10. creationTimestamp: '2020-09-20T14:48:35Z'
  11. annotations:
  12. deployment.kubernetes.io/revision: '1'
  13. kubectl.kubernetes.io/last-applied-configuration: >
  14. {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"nginx-dev","namespace":"default"},"spec":{"selector":{"matchLabels":{"app":"nginx"}},"template":{"metadata":{"labels":{"app":"nginx"}},"spec":{"containers":[{"image":"nginx:1.14.2","name":"nginx"}]}}}}
  15. spec:
  16. replicas: 2
  17. selector:
  18. matchLabels:
  19. app: nginx
  20. template:
  21. metadata:
  22. creationTimestamp: null
  23. labels:
  24. app: nginx
  25. spec:
  26. containers:
  27. - name: nginx
  28. image: 'nginx:1.14.2'
  29. resources: {}
  30. terminationMessagePath: /dev/termination-log
  31. terminationMessagePolicy: File
  32. imagePullPolicy: IfNotPresent
  33. restartPolicy: Always
  34. terminationGracePeriodSeconds: 30
  35. dnsPolicy: ClusterFirst
  36. securityContext: {}
  37. schedulerName: default-scheduler
  38. strategy:
  39. type: RollingUpdate
  40. rollingUpdate:
  41. maxUnavailable: 25%
  42. maxSurge: 25%
  43. revisionHistoryLimit: 10
  44. progressDeadlineSeconds: 600
  45. status:
  46. observedGeneration: 1
  47. replicas: 1
  48. updatedReplicas: 1
  49. readyReplicas: 1
  50. availableReplicas: 1
  51. conditions:
  52. - type: Available
  53. status: 'True'
  54. lastUpdateTime: '2020-09-20T14:48:43Z'
  55. lastTransitionTime: '2020-09-20T14:48:43Z'
  56. reason: MinimumReplicasAvailable
  57. message: Deployment has minimum availability.
  58. - type: Progressing
  59. status: 'True'
  60. lastUpdateTime: '2020-09-20T14:48:43Z'
  61. lastTransitionTime: '2020-09-20T14:48:35Z'
  62. reason: NewReplicaSetAvailable
  63. message: ReplicaSet "nginx-dev-59d7cd6545" has successfully progressed.

Notice that the number of replicas is changes from 1 to 2

  1. deployment.apps/nginx-dev edited

Result

  1. NAME READY UP-TO-DATE AVAILABLE AGE
  2. nginx-dev 2/2 2 2 105s