第39章 クラスター容量の分析
39.1. 概要
As a cluster administrator, you can use the cluster capacity tool to view the number of pods that can be scheduled to increase the current resources before they become exhausted, and to ensure any future pods can be scheduled. This capacity comes from an individual node host in a cluster, and includes CPU, memory, disk space, and others.
The cluster capacity tool simulates a sequence of scheduling decisions to determine how many instances of an input pod can be scheduled on the cluster before it is exhausted of resources to provide a more accurate estimation.
ノード間に分散しているすべてのリソースがカウントされないため、残りの割り当て可能な容量は概算となります。残りのリソースのみが分析対象となり、クラスターでのスケジュール可能な所定要件を持つ Pod のインスタンス数という点から消費可能な容量を見積もります。
Pod のスケジューリングはその選択およびアフィニティー条件に基づいて特定のノードセットについてのみサポートされる可能性があります。そのため、クラスターでスケジュール可能な残りの Pod 数を見積もることが困難になる場合があります。
You can run the cluster capacity analysis tool as a stand-alone utility from the command line, or as a job in a pod inside an OpenShift Container Platform cluster. Running it as job inside of a pod enables you to run it multiple times without intervention.
39.2. コマンドラインでのクラスター容量分析の実行
To run the tool on the command line:
$ cluster-capacity --kubeconfig <path-to-kubeconfig> \ --podspec <path-to-pod-spec>
The --kubeconfig
option indicates your Kubernetes configuration file, and the --podspec
option indicates a sample pod specification file, which the tool uses for estimating resource usage. The podspec
specifies its resource requirements as limits
or requests
. The cluster capacity tool takes the pod’s resource requirements into account for its estimation analysis.
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
--verbose
オプションを追加して、クラスター内の各ノードにスケジュールできる Pod 数についての詳細説明を出力できます。
$ cluster-capacity --kubeconfig <path-to-kubeconfig> \ --podspec <path-to-pod-spec> --verbose
出力は以下のようになります。
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)
上記の例では、クラスターにスケジュールできる Pod の見積り数は 52 です。
39.3. Pod 内のジョブとしてのクラスター容量分析の実行
クラスター容量ツールを Pod 内のジョブとして実行すると、ユーザーの介入なしに複数回実行できるという利点があります。クラスター容量ツールをジョブとして実行するには、ConfigMap
を使用する必要があります。
クラスターロールを作成します。
$ 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
サービスアカウントを作成します。
$ oc create sa cluster-capacity-sa
ロールをサービスアカウントに追加します。
$ oc adm policy add-cluster-role-to-user cluster-capacity-role \ system:serviceaccount:default:cluster-capacity-sa
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
クラスター容量分析は、
cluster-capacity-configmap
という名前のConfigMap
を使用してボリュームにマウントされ、入力 Pod 仕様ファイルpod.yaml
はパス/test-pod
のボリュームtest-volume
にマウントされます。ConfigMap
を作成していない場合は、ジョブの作成前にこれを作成します。$ oc create configmap cluster-capacity-configmap \ --from-file=pod.yaml=pod.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 内でアクセスできます。
クラスター容量イメージを Pod のジョブとして実行します。
$ oc create -f cluster-capacity-job.yaml
ジョブログを確認し、クラスター内でスケジュールできる 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)