중간점검 실습 과제

jaeyeon ha·2026년 3월 7일

[교육] Kubernetes

목록 보기
22/34

과제

  1. ~/kube/example 이라는 폴더를 만들어 해당 폴더에서 다음 작업을 수행한다

    [root@master ~/kube]# mkdir ~/kube/example && cd ~/kube/example/
  2. 다음 조건에 맞게 Deployment 컨트롤러를 사용하는 lab_deploy.yaml 파일을 생성하고 동작시킨다

    • pod : 3개
    • labels: rel:stable
    • deploy name : lab-deploy
    • container name : apache-web
    • container image : httpd:2.2
    [root@master ~/kube/08]# mkdir -p ~/kube/example && cd ~/kube/example
    [root@master ~/kube/example]# kubectl api-resources | grep deploy
    deployments                       deploy       apps/v1                                true         Deployment
    [root@master ~/kube/example]# vi lab_deploy.yaml
    [root@master ~/kube/example]# cat lab_deploy.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: lab-deploy
    spec:
      replicas: 3
      selector:
        matchLabels:
          rel: stable
      template:
        metadata:
          name: lab-pod
          labels:
            rel: stable
        spec:
          containers:
          - name: apache-web
            image: httpd:2.2
    [root@master ~/kube/example]# kubectl apply -f lab_deploy.yaml
    deployment.apps/lab-deploy created
    [root@master ~/kube/example]# kubectl get pod
    NAME                          READY   STATUS              RESTARTS   AGE
    lab-deploy-5b6d66bbbd-2pphz   0/1     ContainerCreating   0          4s
    lab-deploy-5b6d66bbbd-qvb7m   0/1     ContainerCreating   0          4s
    lab-deploy-5b6d66bbbd-wtkkz   0/1     ContainerCreating   0          4s
  3. 위의 구성이 완료되었다면, httpd:2.4 버전의 컨테이너를 갖고 있는 파드를 총 6개로 확장하도록 한다.

    • Image version upgrade
    • Scale up 3 to 6
    [root@master ~/kube/example]# kubectl set image deploy lab-deploy apache-web=httpd:2.4
    deployment.apps/lab-deploy image updated
    [root@master ~/kube/example]# kubectl describe pod lab-deploy | grep Image
        Image:          httpd:2.4
        Image ID:       docker-pullable://httpd@sha256:10381816bb7e60ae3a9db3784f2966a8910b6ff07c4da54bd2d62d2671c8ab6e
        Image:          httpd:2.4
        Image ID:       docker-pullable://httpd@sha256:10381816bb7e60ae3a9db3784f2966a8910b6ff07c4da54bd2d62d2671c8ab6e
        Image:          httpd:2.4
        Image ID:       docker-pullable://httpd@sha256:10381816bb7e60ae3a9db3784f2966a8910b6ff07c4da54bd2d62d2671c8ab6e
    [root@master ~/kube/example]# kubectl scale deployment lab-deploy --replicas=6
    deployment.apps/lab-deploy scaled
    [root@master ~/kube/example]# kubectl get pod
    NAME                          READY   STATUS    RESTARTS   AGE
    lab-deploy-86bf6d86fd-8rwh5   1/1     Running   0          3s
    lab-deploy-86bf6d86fd-cb7nz   1/1     Running   0          3s
    lab-deploy-86bf6d86fd-kfzvb   1/1     Running   0          27s
    lab-deploy-86bf6d86fd-lpljr   1/1     Running   0          19s
    lab-deploy-86bf6d86fd-smv9p   1/1     Running   0          23s
    lab-deploy-86bf6d86fd-vgv7s   1/1     Running   0          3s
    [root@master ~/kube/example]# kubectl describe pod lab-deploy | grep Image
        Image:          httpd:2.4
        Image ID:       docker-pullable://httpd@sha256:10381816bb7e60ae3a9db3784f2966a8910b6ff07c4da54bd2d62d2671c8ab6e
        Image:          httpd:2.4
        Image ID:       docker-pullable://httpd@sha256:10381816bb7e60ae3a9db3784f2966a8910b6ff07c4da54bd2d62d2671c8ab6e
        Image:          httpd:2.4
        Image ID:       docker-pullable://httpd@sha256:10381816bb7e60ae3a9db3784f2966a8910b6ff07c4da54bd2d62d2671c8ab6e
        Image:          httpd:2.4
        Image ID:       docker-pullable://httpd@sha256:10381816bb7e60ae3a9db3784f2966a8910b6ff07c4da54bd2d62d2671c8ab6e
        Image:          httpd:2.4
        Image ID:       docker-pullable://httpd@sha256:10381816bb7e60ae3a9db3784f2966a8910b6ff07c4da54bd2d62d2671c8ab6e
        Image:          httpd:2.4
        Image ID:       docker-pullable://httpd@sha256:10381816bb7e60ae3a9db3784f2966a8910b6ff07c4da54bd2d62d2671c8ab6e
  4. 실습이 완료되었다면, Deployment 컨트롤러를 삭제한다

    [root@master ~/kube/example]# kubectl delete deployments.apps lab-deploy
    deployment.apps "lab-deploy" deleted
    [root@master ~/kube/example]# kubectl get all
    NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
    service/kubernetes   ClusterIP   10.233.0.1   <none>        443/TCP   3h25m

0개의 댓글