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

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

7.2.1. OpenShift Container Platform 클러스터 용량 툴 이해

클러스터 용량 툴에서는 더 정확한 추정을 제공하기 위해 리소스가 고갈되기 전에 클러스터에서 예약할 수 있는 입력 Pod의 인스턴스 수를 확인하는 일련의 예약 결정을 시뮬레이션합니다.

참고

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

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

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

7.2.2. 명령줄에서 클러스터 용량 툴 실행

명령줄에서 OpenShift Container Platform 클러스터 용량 툴을 실행하여 클러스터에 예약할 수 있는 Pod의 수를 추정할 수 있습니다.

사전 요구 사항

  • Red Hat Ecosystem Catalog에서 컨테이너 이미지로 사용할 수 있는 OpenShift 클러스터 용량 툴 을 실행합니다.
  • 툴에서 리소스 사용량을 추정하는 데 사용하는 샘플 Pod 사양 파일을 생성합니다. podspec은 리소스 요구 사항을 limits 또는 requests로 지정합니다. 클러스터 용량 툴에서는 추정 분석에 Pod의 리소스 요구 사항을 고려합니다.

    다음은 Pod 사양 입력 예제입니다.

    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

절차

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

  1. 터미널에서 Red Hat 레지스트리에 로그인합니다.

    $ 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 --podspec /cc/pod-spec.yaml \
    --verbose 1
    1
    클러스터의 각 노드에서 예약할 수 있는 Pod 수에 대한 자세한 설명을 출력하기 위해 --verbose 옵션을 추가할 수도 있습니다.

    출력 예

    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입니다.

7.2.3. Pod 내에서 클러스터 용량 툴을 작업으로 실행

Pod 내부에서 클러스터 용량 툴을 작업으로 실행하면 사용자 개입 없이도 여러 번 실행할 수 있다는 장점이 있습니다. 클러스터 용량 툴을 작업으로 실행하려면 ConfigMap 오브젝트를 사용해야 합니다.

사전 요구 사항

클러스터 용량 툴을 다운로드하여 설치합니다.

프로세스

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

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

    $ cat << EOF| oc create -f -

    출력 예

    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"]
    EOF

  2. 서비스 계정을 생성합니다.

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

    $ oc adm policy add-cluster-role-to-user cluster-capacity-role \
        system:serviceaccount:default:cluster-capacity-sa
  4. Pod 사양을 정의하고 생성합니다.

    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
  5. 클러스터 용량 분석은 입력 Pod 사양 파일 pod.yaml을 경로 /test-pod의 볼륨 test-volume에 마운트하도록 cluster-capacity-configmap이라는 ConfigMap 오브젝트를 사용하여 볼륨에 마운트합니다.

    ConfigMap 오브젝트를 생성하지 않은 경우 작업을 생성하기 전에 하나의 오브젝트를 생성합니다.

    $ oc create configmap cluster-capacity-configmap \
        --from-file=pod.yaml=pod.yaml
  6. 아래의 작업 사양 파일 예제를 사용하여 작업을 생성합니다.

    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 사양 파일에 액세스할 수 있습니다.
  7. Pod에서 클러스터 용량 이미지를 작업으로 실행합니다.

    $ oc create -f cluster-capacity-job.yaml
  8. 작업 로그를 확인하여 클러스터에서 예약할 수 있는 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)