2024. 12. 31. 15:01ㆍ카테고리 없음
Remember, you CANNOT edit specifications of an existing POD other than the below.
- spec.containers[*].image
- spec.initContainers[*].image
- spec.activeDeadlineSeconds
- spec.tolerations
For example you cannot edit the environment variables, service accounts, resource limits (all of which we will discuss later) of a running pod. But if you really want to, you have 2 options:
1. Run the kubectl edit pod <pod name> command. This will open the pod specification in an editor (vi editor). Then edit the required properties. When you try to save it, you will be denied. This is because you are attempting to edit a field on the pod that is not editable.

Pod 편집
- 기존 Pod의 사양(Specification)을 편집할 수 있는 필드:
- spec.containers[*].image: 컨테이너 이미지 변경.
- spec.initContainers[*].image: 초기화 컨테이너 이미지 변경.
- spec.activeDeadlineSeconds: Pod의 활성 상태 유지 시간 설정.
- spec.tolerations: Taints를 허용하는 Toleration 설정.
- 편집할 수 없는 필드:
- 환경 변수, 서비스 계정, 리소스 제한 등은 실행 중인 Pod에서 직접 편집할 수 없습니다.
Pod 사양을 편집하려는 경우
- kubectl edit pod <pod-name> 사용:
- 명령어를 실행하면 Pod 사양이 편집기(기본적으로 vi)에 열립니다.
- 편집 후 저장하려고 하면, 수정이 허용되지 않는 필드를 변경한 경우 저장이 거부됩니다.
- 수정이 필요한 경우 대안:
- 옵션 1: 기존 Pod 삭제 후 새롭게 정의된 사양으로 다시 생성.
- 옵션 2: Deployment 또는 ReplicaSet과 같은 상위 리소스를 사용하여 Pod을 관리하고, 해당 리소스를 업데이트하여 변경 사항을 적용.
Deployment 편집
- Deployment는 Pod보다 더 유연하게 관리됩니다. Deployment를 통해 Pod의 템플릿을 수정하면 새로운 설정으로 자동 롤아웃됩니다.
- 명령어:
kubectl edit deployment <deployment-name>
- Deployment 템플릿에서 수정 가능한 주요 항목:
- 컨테이너 이미지 변경.
- 환경 변수 추가/수정.
- 리소스 요청 및 제한 설정.
- 레이블 및 어노테이션 추가 등.
중요한 점
- Pod 직접 수정은 제한적이며, 대부분의 경우 Deployment와 같은 상위 리소스를 활용하는 것이 권장됩니다.
- Deployment를 사용하면 수정된 설정이 새로운 Pod에 자동으로 반영되며, 롤백과 같은 관리 작업도 용이합니다.
A copy of the file with your changes is saved in a temporary location as shown above.
You can then delete the existing pod by running the command:
kubectl delete pod webapp
Then create a new pod with your changes using the temporary file
kubectl create -f /tmp/kubectl-edit-ccvrq.yaml
2. The second option is to extract the pod definition in YAML format to a file using the command
kubectl get pod webapp -o yaml > my-new-pod.yaml
Then make the changes to the exported file using an editor (vi editor). Save the changes
vi my-new-pod.yaml
Then delete the existing pod
kubectl delete pod webapp
Then create a new pod with the edited file
kubectl create -f my-new-pod.yaml
Edit Deployments
With Deployments you can easily edit any field/property of the POD template. Since the pod template is a child of the deployment specification, with every change the deployment will automatically delete and create a new pod with the new changes. So if you are asked to edit a property of a POD part of a deployment you may do that simply by running the command
kubectl edit deployment my-deployment
파일에 대한 변경 사항이 임시 위치에 저장되었음을 나타냅니다.기존 Pod를 삭제하려면 다음 명령어를 실행하세요:
그런 다음, 임시 파일을 사용하여 변경된 내용을 반영한 새 Pod를 생성합니다:
kubectl delete pod webapp
kubectl create -f /tmp/kubectl-edit-ccvrq.yaml
두 번째 옵션
Pod 정의를 YAML 형식으로 파일에 추출한 후 편집할 수 있습니다. 다음 단계를 따르세요:
- Pod 정의를 파일로 내보냅니다:
- 내보낸 파일을 편집기(예: vi)로 열어 수정합니다:
- 기존 Pod를 삭제합니다:
- 수정된 파일을 사용하여 새 Pod를 생성합니다:
kubectl get pod webapp -o yaml > my-new-pod.yaml
vi my-new-pod.yaml
kubectl delete pod webapp
kubectl create -f my-new-pod.yaml
Deployment 편집
Deployment에서는 Pod 템플릿의 모든 필드/속성을 쉽게 수정할 수 있습니다. Pod 템플릿은 Deployment 사양의 하위 항목이므로, 변경 사항이 적용될 때마다 Deployment는 자동으로 기존 Pod를 삭제하고 새로운 설정으로 새 Pod를 생성합니다.Deployment의 Pod 속성을 수정하려면 아래 명령어를 실행하세요:
kubectl edit deployment my-deployment
이렇게 하면 Deployment와 연결된 모든 Pod가 자동으로 업데이트됩니다.