This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.第20章 ガベージコレクション
20.1. 概要 リンクのコピーリンクがクリップボードにコピーされました!
OpenShift Container Platform ノードは、2 種類のガベージコレクションを実行します。
- Container garbage collection: Removes terminated containers.
 - Image garbage collection: Removes images not referenced by any running pods.
 
20.2. コンテナーのガベージコレクション リンクのコピーリンクがクリップボードにコピーされました!
				コンテナーのガベージコレクションはデフォルトで有効にされ、エビクションのしきい値に達すると自動的に実行されます。ノードは Pod のコンテナーを API からアクセス可能な状態にしようとします。Pod が削除された場合、コンテナーも削除されます。コンテナーは Pod が削除されておらず、エビクションのしきい値に達していない限り保持されます。ノードがディスク不足 (disk pressure) の状態にある場合、コンテナーが削除され、それらのログは oc logs でアクセスできなくなります。
			
コンテナーのガベージコレクションのポリシーは 3 つのノード設定に基づいています。
| 設定 | 説明 | 
|---|---|
| 
							 
								  | 
							 コンテナーがガベージコレクションの対象となるのに必要な最小の年数です。デフォルトは 0 です。制限なしにするには 0 を使用します。この設定の値は、時間の h、分の m、秒の s などの単位のサフィックスを使用して指定することができます。  | 
| 
							 
								  | 
							 The number of instances to retain per pod container. The default is 1.  | 
| 
							 
								  | 
							 ノードにある実行されないコンテナーの合計の最大数です。デフォルトは、無制限を意味する -1 です。  | 
				競合が生じる場合、maximum-dead-containers 設定は maximum-dead-containers-per-container 設定よりも優先されます。たとえば、maximum-dead-containers-per-container の数を保持することでコンテナーの合計数が maximum-dead-containers より大きくなる場合、最も古いコンテナーが削除され、maximum-dead-containers の制限が満たされるようにします。
			
ノードが実行されていないコンテナーを削除すると、それらのコンテナーの内部にあるすべてのファイルも削除されます。そのノードで作成されたコンテナーに対してのみガベージコレクションが実行されます。
				You can specify values for these settings in the kubeletArguments section of the /etc/origin/node/node-config.yaml file on node hosts. Add the section if it does not already exist:
			
コンテナーのガベージコレクション設定
20.2.1. 削除するコンテナーの検出 リンクのコピーリンクがクリップボードにコピーされました!
ガべージコレクターの各ループでは、以下の手順が実行されます。
- Retrieve a list of available containers.
 - 
							Filter out all containers that are running or are not alive longer than the 
minimum-container-ttl-durationparameter. - Classify all remaining containers into equivalence classes based on pod and image name membership.
 - Remove all unidentified containers (containers that are managed by kubelet but their name is malformed).
 - 
							For each class that contains more containers than the 
maximum-dead-containers-per-containerparameter, sort containers in the class by creation time. - 
							Start removing containers from the oldest first until the 
maximum-dead-containers-per-containerparameter is met. - 
							依然として 
maximum-dead-containersパラメーターよりも多くのコンテナーが一覧にある場合、コレクターは各クラスのコンテナーの削除を開始し、それぞれのクラスにあるコンテナー数がクラスあたりのコンテナーの平均数、または<all_remaining_containers>/<number_of_classes>よりも大きくならないようにします。 - 
							If this is still not enough, sort all containers in the list and start removing containers from the oldest first until the 
maximum-dead-containerscriterion is met. 
各種のニーズに合わせてデフォルト設定を更新してください。
ガべージコレクションは、関連付けられている Pod のないコンテナーのみを削除します。
20.3. イメージのガベージコレクション リンクのコピーリンクがクリップボードにコピーされました!
イメージのガべージコレクションでは、ノードの cAdvisor によって報告されるディスク使用量に基づいて、ノードから削除するイメージを決定します。この場合、以下の設定が考慮に入れられます。
| 設定 | 説明 | 
|---|---|
| 
							 
								  | 
							 The percent of disk usage (expressed as an integer) which triggers image garbage collection. The default is 85.  | 
| 
							 
								  | 
							 The percent of disk usage (expressed as an integer) to which image garbage collection attempts to free. Default is 80.  | 
				You can specify values for these settings in the kubeletArguments section of the /etc/origin/node/node-config.yaml file on node hosts. Add the section if it does not already exist:
			
イメージのガベージコレクション設定
kubeletArguments:
  image-gc-high-threshold:
    - "85"
  image-gc-low-threshold:
    - "80"
kubeletArguments:
  image-gc-high-threshold:
    - "85"
  image-gc-low-threshold:
    - "80"
20.3.1. 削除するイメージの検出 リンクのコピーリンクがクリップボードにコピーされました!
以下の 2 つのイメージ一覧がそれぞれのガベージコレクターの実行で取得されます。
- 1 つ以上の Pod で現在実行されているイメージの一覧
 - ホストで利用可能なイメージの一覧
 
新規コンテナーの実行時に新規のイメージが表示されます。すべてのイメージにはタイムスタンプのマークが付けられます。イメージが実行中 (上記の最初の一覧) か、または新規に検出されている (上記の 2 番目の一覧) 場合、これには現在の時間のマークが付けられます。残りのイメージには以前のタイムスタンプのマークがすでに付けられています。すべてのイメージはタイムスタンプで並び替えられます。
コレクションが開始されると、停止条件を満たすまでイメージが最も古いものから順番に削除されます。