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)

Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.