Exercise 3.4: Deploy A Sample Application

  1. Deployment 생성

    kubectl create deployment nginx --image=nginx
  2. Deployment 상태 확인

    kubectl get deploy
  3. Pod가 생성되었는지 확인

    kubectl get pod
  4. 생성된 NGINX Deployment 상태 상세 확인

    kubectl describe deployment nginx 
  5. 클러스터에 발생한 이벤트 확인

    kubectl get events  --sort-by='.metadata.creationTimestamp'
  6. 생성된 NGINX Deployment의 Manifest를 YAML 형식으로 출력

    kubectl get deploy nginx -o yaml
  7. 생성된 NGINX Deployment의 Manifest를 YAML 형식으로 저장

    kubectl get deploy nginx -o yaml > first.yaml
  8. first.yaml 파일을 텍스트 에디터에서 열고 아래와 같이 수정하세요.

    • creationTimestamp, resourceVersion, uid 를 포함하는 라인 삭제

    • status 아래의 모든 라인 삭제 (status 포함)

    • 수정 완료 버전

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        annotations:
          deployment.kubernetes.io/revision: "1"
        generation: 1
        labels:
          app: nginx
        name: nginx
        namespace: default
      spec:
        progressDeadlineSeconds: 600
        replicas: 1
        revisionHistoryLimit: 10
        selector:
          matchLabels:
            app: nginx
        strategy:
          rollingUpdate:
            maxSurge: 25%
            maxUnavailable: 25%
          type: RollingUpdate
        template:
          metadata:
            creationTimestamp: null
            labels:
              app: nginx
          spec:
            containers:
            - image: nginx
              imagePullPolicy: Always
              name: nginx
              resources: {}
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
            dnsPolicy: ClusterFirst
            restartPolicy: Always
            schedulerName: default-scheduler
            securityContext: {}
            terminationGracePeriodSeconds: 30
  9. NGINX Deployment 삭제

    kubectl delete deploy nginx
  10. 위에서 생성한 first.yaml 파일을 이용해서 Deployment 생성

    kubectl apply -f first.yaml
  11. Deployment 상태 확인

    kubectl get deploy
  12. 새로 생성된 NGINX Deployment의 Manifest를 YAML 형식으로 저장

    kubectl get deploy nginx -o yaml > second.yaml
  13. 두개의 YAML 파일을 비교

    diff first.yaml second.yaml -y
  14. Deployment의 resourceVersion 값 확인

    kubectl get deploy nginx -o=jsonpath='{.metadata.resourceVersion}{"\n"}'
  15. Deployment에 속하는 Pod 삭제

    kubectl delete pod -l app=nginx
  16. Deployment의 resourceVersion 값을 다시 확인

    kubectl get deploy nginx -o=jsonpath='{.metadata.resourceVersion}{"\n"}'
  17. dry-run 옵션으로 실제 리소스를 생성하지 않고 Manifest만 확인

    kubectl create deployment nginx --image=nginx --dry-run=client -o yaml
  18. NGINX Deployment의 Manifest를 JSON 형식으로 출력

    kubectl get deployment nginx -o json
  19. NGINX Deployment에 서비스 생성

    kubectl expose deployment/nginx 
  20. kubectl expose 명령어에 대한 도움말 보기

    kubectl expose -h
  21. first.yaml 파일의 spec.templates.spec.containers 부분을 아래와 같이 수정

    ....
        spec:
          containers:
          - image: nginx
            imagePullPolicy: Always
            name: nginx
            ports:
            - containerPort: 80
              protocol: TCP
    ....
  22. first.yaml 파일의 수정 완료 버전

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        deployment.kubernetes.io/revision: "1"
      generation: 1
      labels:
        app: nginx
      name: nginx
      namespace: default
    spec:
      progressDeadlineSeconds: 600
      replicas: 1
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: nginx
      strategy:
        rollingUpdate:
          maxSurge: 25%
          maxUnavailable: 25%
        type: RollingUpdate
      template:
        metadata:
          creationTimestamp: null
          labels:
            app: nginx
        spec:
          containers:
          - image: nginx
            imagePullPolicy: Always
            name: nginx
            ports:
            - containerPort: 80
              protocol: TCP
            resources: {}
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
  23. 변경사항 반영

    kubectl apply -f first.yaml
  24. Deployment와 Pod가 새로 생성됐는지 확인

    kubectl get deploy,rs,pod 
  25. NGINX Deployment에 서비스 생성

    kubectl expose deployment/nginx
  26. NGINX 서비스 확인

    kubectl get svc nginx
  27. NGINX 서비스에 연결된 Endpoints 확인

    kubectl get ep nginx
  28. 현재 배포된 Pod의 IP 주소 확인

    kubectl get pod -l app=nginx -o wide
  29. Worker 노드에 연결된 터미널로 이동해서 트래픽 캡쳐

    sudo tcpdump -i cilium_vxlan
  30. CP 노드에 연결된 터미널로 이동해서 NGINX 서비스의 ClusterIP에 HTTP 요청

    curl NGINX_SVC_CLUSTER_IP 

    OR

    curl $(kubectl get svc nginx -o=jsonpath='{.spec.clusterIP}')
  31. Worker 노드에 연결된 터미널로 이동해서 트래픽 캡쳐 결과 확인 하고 tcpdump 프로세스 종료

  32. CP 노드에 연결된 터미널로 돌아와서 노드의 IP 주소 확인

    ip a
  33. Cilium을 통해서 생성된 사용자 지정 객체 확인

    kubectl get ciliumnodes
  34. NGINX 서비스에 연결된 Endpoints 주소로 HTTP 요청

    curl NGINX_ENDPOINT_IP

    OR

    curl $(kubectl get ep nginx -o=jsonpath='{.subsets[0].addresses[0].ip}:{.subsets[0].ports[0].port}')
  35. NGINX Deployment의 Replica 갯수를 3개로 변경

    kubectl scale deployment nginx --replicas=3
  36. Pod가 추가로 생성됐는지 확인

    kubectl get pod -l app=nginx -o wide
  37. NGINX 서비스에 연결된 Endpoints 확인

    kubectl get ep nginx

Last updated