8.2. OpenShift Container Platform 노드에서 보유할 수 있는 Pod 수 추정

클러스터 관리자는 OpenShift Cluster Capacity Tool을 사용하여 현재 리소스가 소진되기 전에 현재 리소스를 늘리기 전에 예약할 수 있는 Pod 수를 확인하고 향후 포드를 예약할 수 있습니다. 이러한 용량은 클러스터의 개별 노드 호스트에서 제공하며 CPU, 메모리, 디스크 공간 등을 포함합니다.

8.2.1. OpenShift Cluster Capacity 툴 이해

OpenShift Cluster Capacity Tool은 보다 정확한 추정을 제공하기 위해 리소스가 소진되기 전에 클러스터에서 예약할 수 있는 입력 포드의 인스턴스 수를 결정하기 위해 일련의 스케줄링 결정을 시뮬레이션합니다.

참고

나머지 할당 가능 용량은 여러 노드에 배포되는 모든 리소스를 계산하지 않기 때문에 대략적인 추정치입니다. 남은 리소스만 분석하고 클러스터에서 예약할 수 있는 지정된 요구 사항이 포함된 Pod의 여러 인스턴스 측면에서 여전히 사용할 수 있는 가용 용량을 추정합니다.

또한 Pod는 선택 및 유사성 기준에 따라 특정 노드 집합에서만 예약 기능이 지원될 수 있습니다. 이로 인해 클러스터에서 예약할 수 있는 나머지 Pod를 추정하기 어려울 수 있습니다.

OpenShift Cluster Capacity Tool을 명령줄에서 독립형 유틸리티로 실행하거나 OpenShift Container Platform 클러스터 내부의 Pod에서 작업으로 실행할 수 있습니다. Pod 내에서 툴을 작업으로 실행하면 개입 없이 여러 번 실행할 수 있습니다.

8.2.2. 명령줄에서 OpenShift Cluster Capacity Tool 실행

명령줄에서 OpenShift Cluster Capacity Tool을 실행하여 클러스터에 예약할 수 있는 포드 수를 추정할 수 있습니다.

툴에서 리소스 사용량을 추정하는 데 사용하는 샘플 Pod 사양 파일을 생성합니다. Pod 사양은 리소스 요구 사항을 제한 또는 요청으로 지정합니다. 클러스터 용량 툴에서는 추정 분석에 Pod의 리소스 요구 사항을 고려합니다.

사전 요구 사항

  1. Red Hat Ecosystem Catalog의 컨테이너 이미지로 사용할 수 있는 OpenShift Cluster Capacity Tool 을 실행합니다.
  2. 샘플 Pod 사양 파일을 생성합니다.

    1. 다음과 유사한 YAML 파일을 생성합니다.

      apiVersion: v1
      kind: Pod
      metadata:
        name: small-pod
        labels:
          app: guestbook
          tier: frontend
      spec:
        containers:
        - name: php-redis
          image: gcr.io/google-samples/gb-frontend:v4
          imagePullPolicy: Always
          resources:
            limits:
              cpu: 150m
              memory: 100Mi
            requests:
              cpu: 150m
              memory: 100Mi
    2. 클러스터 역할을 생성합니다.

      $ oc create -f <file_name>.yaml

      예를 들면 다음과 같습니다.

      $ oc create -f pod-spec.yaml

절차

명령줄에서 클러스터 용량 툴을 사용하려면 다음을 수행합니다.

  1. 터미널에서 Red Hat Registry에 로그인합니다.

    $ podman login registry.redhat.io
  2. 클러스터 용량 툴 이미지를 가져옵니다.

    $ podman pull registry.redhat.io/openshift4/ose-cluster-capacity
  3. 클러스터 용량 툴을 실행합니다.

    $ podman run -v $HOME/.kube:/kube:Z -v $(pwd):/cc:Z  ose-cluster-capacity \
    /bin/cluster-capacity --kubeconfig /kube/config --<pod_spec>.yaml /cc/<pod_spec>.yaml \
    --verbose

    다음과 같습니다.

    <pod_spec>.yaml
    사용할 Pod 사양을 지정합니다.
    상세 정보
    클러스터의 각 노드에서 예약할 수 있는 Pod 수에 대한 자세한 설명을 출력합니다.

    출력 예

    small-pod pod requirements:
    	- CPU: 150m
    	- Memory: 100Mi
    
    The cluster can schedule 88 instance(s) of the pod small-pod.
    
    Termination reason: Unschedulable: 0/5 nodes are available: 2 Insufficient cpu,
    3 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't
    tolerate.
    
    Pod distribution among nodes:
    small-pod
    	- 192.168.124.214: 45 instance(s)
    	- 192.168.124.120: 43 instance(s)

    위 예에서 클러스터에 예약할 수 있는 예상 Pod 수는 88입니다.

8.2.3. Pod 내에서 OpenShift Cluster Capacity Tool을 작업으로 실행

포드 내에서 OpenShift Cluster Capacity Tool을 작업으로 실행하면 사용자 개입 없이도 툴을 여러 번 실행할 수 있습니다. ConfigMap 오브젝트를 사용하여 OpenShift Cluster Capacity Tool을 작업으로 실행합니다.

사전 요구 사항

OpenShift Cluster Capacity 툴 을 다운로드하여 설치합니다.

프로세스

클러스터 용량 툴을 실행하려면 다음을 수행합니다.

  1. 클러스터 역할을 생성합니다.

    1. 다음과 유사한 YAML 파일을 생성합니다.

      kind: ClusterRole
      apiVersion: rbac.authorization.k8s.io/v1
      metadata:
        name: cluster-capacity-role
      rules:
      - apiGroups: [""]
        resources: ["pods", "nodes", "persistentvolumeclaims", "persistentvolumes", "services", "replicationcontrollers"]
        verbs: ["get", "watch", "list"]
      - apiGroups: ["apps"]
        resources: ["replicasets", "statefulsets"]
        verbs: ["get", "watch", "list"]
      - apiGroups: ["policy"]
        resources: ["poddisruptionbudgets"]
        verbs: ["get", "watch", "list"]
      - apiGroups: ["storage.k8s.io"]
        resources: ["storageclasses"]
        verbs: ["get", "watch", "list"]
    2. 다음 명령을 실행하여 클러스터 역할을 생성합니다.

      $ oc create -f <file_name>.yaml

      예를 들면 다음과 같습니다.

      $ oc create sa cluster-capacity-sa
  2. 서비스 계정을 생성합니다.

    $ oc create sa cluster-capacity-sa -n default
  3. 서비스 계정에 역할을 추가합니다.

    $ oc adm policy add-cluster-role-to-user cluster-capacity-role \
        system:serviceaccount:<namespace>:cluster-capacity-sa

    다음과 같습니다.

    <namespace>
    Pod가 있는 네임스페이스를 지정합니다.
  4. Pod 사양을 정의하고 생성합니다.

    1. 다음과 유사한 YAML 파일을 생성합니다.

      apiVersion: v1
      kind: Pod
      metadata:
        name: small-pod
        labels:
          app: guestbook
          tier: frontend
      spec:
        containers:
        - name: php-redis
          image: gcr.io/google-samples/gb-frontend:v4
          imagePullPolicy: Always
          resources:
            limits:
              cpu: 150m
              memory: 100Mi
            requests:
              cpu: 150m
              memory: 100Mi
    2. 다음 명령을 실행하여 Pod를 생성합니다.

      $ oc create -f <file_name>.yaml

      예를 들면 다음과 같습니다.

      $ oc create -f pod.yaml
  5. 다음 명령을 실행하여 구성 맵 오브젝트를 생성했습니다.

    $ oc create configmap cluster-capacity-configmap \
        --from-file=pod.yaml=pod.yaml

    클러스터 용량 분석은 입력 Pod 사양 파일 pod.yaml 을 경로 /test-pod 의 볼륨 test-volume 에 마운트하기 위해 cluster-capacity-configmap 이라는 구성 맵 오브젝트를 사용하여 볼륨에 마운트됩니다.

  6. 아래의 작업 사양 파일 예제를 사용하여 작업을 생성합니다.

    1. 다음과 유사한 YAML 파일을 생성합니다.

      apiVersion: batch/v1
      kind: Job
      metadata:
        name: cluster-capacity-job
      spec:
        parallelism: 1
        completions: 1
        template:
          metadata:
            name: cluster-capacity-pod
          spec:
              containers:
              - name: cluster-capacity
                image: openshift/origin-cluster-capacity
                imagePullPolicy: "Always"
                volumeMounts:
                - mountPath: /test-pod
                  name: test-volume
                env:
                - name: CC_INCLUSTER 1
                  value: "true"
                command:
                - "/bin/sh"
                - "-ec"
                - |
                  /bin/cluster-capacity --podspec=/test-pod/pod.yaml --verbose
              restartPolicy: "Never"
              serviceAccountName: cluster-capacity-sa
              volumes:
              - name: test-volume
                configMap:
                  name: cluster-capacity-configmap
      1
      클러스터 용량 툴에 클러스터 내에서 Pod로 실행되고 있음을 알리는 필수 환경 변수입니다.
      ConfigMap 오브젝트의 pod.yaml 키는 필수는 아니지만 Pod 사양 파일의 이름과 동일합니다. 이렇게 하면 Pod 내부에서 /test-pod/pod.yaml로 입력 Pod 사양 파일에 액세스할 수 있습니다.
    2. 다음 명령을 실행하여 Pod에서 클러스터 용량 이미지를 작업으로 실행합니다.

      $ oc create -f cluster-capacity-job.yaml

검증

  1. 작업 로그를 확인하여 클러스터에서 예약할 수 있는 Pod 수를 찾습니다.

    $ oc logs jobs/cluster-capacity-job

    출력 예

    small-pod pod requirements:
            - CPU: 150m
            - Memory: 100Mi
    
    The cluster can schedule 52 instance(s) of the pod small-pod.
    
    Termination reason: Unschedulable: No nodes are available that match all of the
    following predicates:: Insufficient cpu (2).
    
    Pod distribution among nodes:
    small-pod
            - 192.168.124.214: 26 instance(s)
            - 192.168.124.120: 26 instance(s)