ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [55일차] yaml 명세를 이용해 로컬 배포
    교육/코드스테이츠 2023. 2. 14. 18:43

    https://zdnet.co.kr/view/?no=20220722100024

    시나리오

    CozServer라는 간단한 WAS가 있다. 버전 1.0은 정상적으로 잘 작동하는 애플리케이션으로. 여기에 디플로이먼트 명세를 적용해서 파드의 레플리카를 배포할 것이다. 이후에 2.0 버전을 만들고, 디플로이먼트를 이용해 업데이트를 적용한다

    여기서 3.0 버전에 의도적으로 버그를 만든다. 3.0 버전에 문제가 발생하면, 2.0 버전으로 롤백해야 한다. 이러한 과정을 통해 실질적으로 서비스 전체에 문제가 생기는 것을 막아볼 것.

     

    • 목표

    파드 명세를 작성할 수 있다.

    디플로이먼트 명세를 작성할 수 있다.

    서비스를 이용해 파드를 노출할 수 있다.

    kubectl apply 명령을 이용해 리소스를 생성할 수 있다.

    디플로이먼트 명세를 수정(또는 재작성)하여 새로운 버전을 배포할 수 있다.

    kubectl rollout 명령을 이용해 롤링 배포 현황을 확인할 수 있다.

    새로운 버전에 문제가 발생했을 때 롤백할 수 있다.

     

    1. 파드 명세

    apiVersion: v1
    kind: Pod
    metadata:
      name: cozserver
    spec:
      containers:
      - name: cozserver
        image: sebcontents/cozserver:1.0
        ports:
        - containerPort: 8080

     

    2. 디플로이먼트 명세

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: cozserver-deploy
      labels:
        app: cozserver-deploy-v1
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: cozserver
      template:
        metadata:
          labels:
            app: cozserver
        spec:
          containers:
          - name: cozserver
            image: sebcontents/cozserver:1.0
            ports:
            - containerPort: 8080

     

    3. 서비스

    apiVersion: v1
    kind: Service
    metadata:
      name: cozserver-service
    spec:
      selector:
        app: cozserver
      ports:
        - protocol: TCP
          port: 80
          targetPort: 8080
      type: LoadBalancer

    4. 모든 명세는 kubectl apply -f <yaml 파일 이름> 으로 실행시킨다.

    기록을 남길려면 뒤에 --record를 더해주면 된다.

     

    5. 디플로이먼트의 이미지는 spec안 containers에 image 부분만 바꿔주면 된다

        spec:
          containers:
          - name: cozserver
            image: sebcontents/cozserver:1.0    >    image: sebcontents/cozserver:2.0

     

    6. kubectl rollout 명령을 이용해 롤링 배포 현황을 확인할 수 있다.

    kubectl rollout history <type> <image> 를 이용해 --record로 기록한 내용을 확인한다

    REVISION CHANGE-CAUSE
    1 kubectl apply --cluster=minikube --filename=cozserver-deployment-v1.yaml --record=true
    2 kubectl apply --cluster=minikube --filename=cozserver-deployment-v2.yaml --record=true
    3 kubectl apply --cluster=minikube --filename=cozserver-deployment-v3.yaml --record=true

     

    7. 새로운 버전에 문제가 발생했을 때 롤백할 수 있다.

    kubectl rollout undo <type> <name> 을 이용해 롤백 할 수있다

    REVISION CHANGE-CAUSE
    1 kubectl apply --cluster=minikube --filename=cozserver-deployment-v1.yaml --record=true
    3 kubectl apply --cluster=minikube --filename=cozserver-deployment-v3.yaml --record=true
    4 kubectl apply --cluster=minikube --filename=cozserver-deployment-v2.yaml --record=true

     

Designed by Tistory.