Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

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

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

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

    $ cat << EOF| oc create -f -
    kind: ClusterRole
    apiVersion: v1
    metadata:
      name: cluster-capacity-role
    rules:
    - apiGroups: [""]
      resources: ["pods", "nodes", "persistentvolumeclaims", "persistentvolumes", "services"]
      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 1
    1
    서비스 계정이 default 프로젝트에 없는 경우 default 를 프로젝트 이름으로 바꿉니다.
  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
  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: registry.redhat.io/openshift3/ose-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로 실행되고 있음을 알리는 필수 환경 변수입니다.
    ConfigMappod.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)