DevOps/CKA Test 준비

03.CKA-Delpoyement 초안

치킨맛코드 2023. 1. 10. 08:45

강의 내용을 정리한 것 입니다.

 

pod를 직접 관리하면 해당 내용에 대해 확인하기 쉽지만, 그렇기에는 시간과 물리적인 환경이 힘들다. 그렇기에 중간지점에서 관리해 줄 수 있는 하나의 기능을 만들었는데, 이것이 Deployment이다. 가장 흔히 사용하는 api중 하나이다. 보통 replicaset과 rolling/rollback기능을 활용하기 위해 사용한다.

 

Delpoyement의 일반적인 yaml양식은 아래와 같다.

 

"

 

apiVersion : apps/v1
==>api의 버전을 명시한다.


kind: Deployment
==> 해당 api의 종류를 명시(Deployment) 한다.

 

metadata:
    name: deploy-nginx
==> 해당 정보에대한 메타데이터를 생성한다.

 

spec:
   replicas: 2

==> 해당 deployment가 유지할 최소 Pod갯수를 지정한다.

 

    selector:
        mataLabels:
          app: webui

==> template에서 참조하기 위한 Labels값을 명시 한다.       

 

    template:
==> deployment가 운용하기 위해 필수적으로 사용하는 정보를 명시한다.

 

      metadata:
        labels:
          app:webui
==> mataLabels에서 명시한 app 참조한다.

 

    spec:
      containers:
      - name: nginx-container
         image: nginx:1.14
==> 해당 컨테이너의 스펙 산정. 컨테이너 명과 사용할 이미지 명시한다.

 

"

https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

 

Deployments

A Deployment provides declarative updates for Pods and ReplicaSets. You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new Rep

kubernetes.io

 

<문제.01 Deplyoment생성 및 replicas 활용>
deployment를 생성한 후 해당 컨테이너의 pod수를 3개로 확장 하시오.

 

<조건>
deployment 명 : webserver
replicas : 2
label : app_env_stage=dev
container name : webserver
container image: nginx1.14

 

<풀이과정>

deployment yaml을 먼저 생성한다.=>생성한 yaml값을 변경한다.=> replicase을 변경한다.

 

1.yaml을 먼저 생성한다.

==> kubectl create deployment webserver --image=nginx:1.14 --replicas=2 --dry-run=clinet -o yaml > webserver.yaml

deployment를 생성할 건데, 이름은 webserver로, 이미지는 nginx로, 버전은 1.14 replicas는 2개로 설정한다. 해당 deployment의 yaml값을 webserver.yaml이라는 파일에 설정해 두기로 한다.

2. yaml 값을 아래와 같이 변경한다.

==> vi webserver.yaml

 

webserver.yaml

apiVersion: apps/v1
kind : Deployment
==> 해당 app의 종류를 지정한다.
metadata:
    name: webserver
==> 해당 deployment의 이름을 지정한다.
spec:
   replicas:2
==> replicas를 2개로 지정한다.
   selector:
      matchLabels:
         app_env_stage: dev
==> label : app_env_stage=dev 해당 값에 대한 metadata를 지정한다.
      template:
         metadata:
             labels:
               app_env_stage: dev
==> label : app_env_stage=dev 해당 값에 대한 metadata를 지정한다.
         spec:
           conainer:
           - image: nginx:1.14
==> container 의 image version을 지정한다.
             name: webserver
==> container의 이름을 지정한다.

3. replicase를 3개로 변경해 pod수를 확장한다.

==> kubectl scal deployment webserver --replicase=3



<문제.02 scale in/out 활용하기>
해당 namespace를 통해 배포된 app이 있다. 이 app에 대한 pod를 5개로 scale-out하며, 해당 pod의 name을 아래의 경로에 기록해라.

 

<조건>
namespace : devops
app name : eshop-order
pod name 경로 : /opt/REPORT/2022/eshop-order-pod-list

 

<풀이과정>

배포된 엡 확인하기 => app의 갯수 확인하기 => scale out 하기 => 이름을 확인한 후 cat혹은 vi 명령어 등을 사용하여 이름 기록하기

 




<문제.03 rolling update활용하기>
Deployment를 이용해 nginx pod를 3개 배포하시오. 그 다음 container image version을 rolling update하고 해당 record를 기록합니다. 이 후 해당 image를 previous version으로 roll back하시오.

<조건>
name : eshop-payment
image: nginx
image version : 1.16
update image version : 1.17
label: app= payment, evbironment=production

<풀이과정>

deployment yaml을 먼저 생성한다.=>생성한 yaml값을 변경한다.=> replicase을 변경한다.