Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

전공공부

[K8S - CKA] Kubectl Apply Command 본문

Study/K8S

[K8S - CKA] Kubectl Apply Command

monitor 2023. 8. 26. 22:58

어떻게 kubectl 명령어가 적용이 되는지 알아보자.

Local file을 이용해서 apply 명령어를 적용하면 쿠버네티스 내장 메모리에 오브젝트를 만든다.

yaml 파일로 저장한 것은 Last applied Configuration (json) 파일로 변화가 됩니다. 이때 메모리와 yaml 파일 그리고 json 파일로 변환된 파일이 어떻게 상호 작용하는지 알아봅시다.

nginx update to 18 -> 19로 업데이트가 될 때를 생각해봅시다.

Local yaml 파일에서 우선 update를 할 것이고 그럼, k8s object가 이를 인지하고 바뀌게 됩니다.

그리고, Last applied Configuration을 저장하는 json이 바뀐 버전으로 업데이트 됩니다.

그러면 이때, Last applied Configuration 파일은 왜 필요 할까요?

 

-> 이전과 달라진 변경점을 알기 위해서 입니다. 아래 예시를 봅시다.

 

Local yaml에서 필드를 삭제하고 싶으면 필드를 삭제하고 적용 명령어를 사용하면 적용이 된다.

하지만 내부적으로는 Live Object Configuration과 Local file만 보고 판단하여 필드 삭제됌을 판단하는 것이 아닌

Last applied Configuration 파일과 Local yaml 파일의 변경점을 보고 판단하여 삭제한다.


Last applied Configuration json 파일은 어디에 있을까요?

바로 Live Object configuration 파일의

metadata.annotations.kubectl.kubernetes.io/last-applied-configuration 해당 부분에 json으로 저장 되어 있습니다.

kind: Deployment
metadata:
  annotations:
    # ...
    # This is the json representation of simple_deployment.yaml
    # It was written by kubectl apply when the object was created
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apps/v1","kind":"Deployment",
      "metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},
      "spec":{"minReadySeconds":5,"selector":{"matchLabels":{"app":nginx}},"template":{"metadata":{"labels":{"app":"nginx"}},
      "spec":{"containers":[{"image":"nginx:1.14.2","name":"nginx",
      "ports":[{"containerPort":80}]}]}}}}      
  # ...
spec:
  # ...
  minReadySeconds: 5
  selector:
    matchLabels:
      # ...
      app: nginx
  template:
    metadata:
      # ...
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:1.14.2
        # ...
        name: nginx
        ports:
        - containerPort: 80
        # ...
      # ...
    # ...
  # ...