Red Hat Training
A Red Hat training course is available for OpenShift Container Platform
第25章 Daemonset の使用
25.1. 概要
daemonset は、OpenShift Container Platform クラスター内の特定の、またはすべてのノードで Pod のレプリカを実行するために使用できます。
daemonset を使用して共有ストレージを作成し、クラスターのすべてのノードでロギング Pod を実行するか、またはすべてのノードでモニターエージェントをデプロイします。
セキュリティー上の理由により、クラスター管理者のみが daemonset を作成できます (ユーザーへの Daemonset パーミッションの付与)。
daemonset についての詳細は、Kubernetes ドキュメントを参照してください。
Daemonset のスケジューリングにはプロジェクトのデフォルトノードセレクターとの互換性がありません。これを無効にしない場合、daemonset はデフォルトのノードセレクターとのマージによって制限されます。これにより、マージされたノードセレクターで選択解除されたノードで Pod が頻繁に再作成されるようになり、クラスターに不要な負荷が加わります。
そのため、以下に留意してください。
-
daemonset の使用を開始する前に、namespace のアノテーション
openshift.io/node-selector
を空の文字列に設定することで、デフォルトのプロジェクト全体の「ノードセレクター」を namespace で無効にします。
# oc patch namespace myproject -p \ '{"metadata": {"annotations": {"openshift.io/node-selector": ""}}}'
-
新規プロジェクトを作成している場合、
oc adm new-project --node-selector=""
を使用してデフォルトのノードセレクターを上書きします。
25.2. Daemonset の作成
daemonset の作成時に、nodeSelector
フィールドは daemonset がレプリカをデプロイする必要のあるノードを指定するために使用されます。
daemonset yaml ファイルを定義します。
apiVersion: extensions/v1beta1 kind: DaemonSet metadata: name: hello-daemonset spec: selector: matchLabels: name: hello-daemonset 1 template: metadata: labels: name: hello-daemonset 2 spec: nodeSelector: 3 type: infra containers: - image: openshift/hello-openshift imagePullPolicy: Always name: registry ports: - containerPort: 80 protocol: TCP resources: {} terminationMessagePath: /dev/termination-log serviceAccount: default terminationGracePeriodSeconds: 10
daemonset オブジェクトを作成します。
oc create -f daemonset.yaml
Pod が作成されていることを確認し、各 Pod に Pod レプリカがあることを確認するには、以下を実行します。
daemonset Pod を検索します。
$ oc get pods hello-daemonset-cx6md 1/1 Running 0 2m hello-daemonset-e3md9 1/1 Running 0 2m
Pod がノードに配置されていることを確認するために Pod を表示します。
$ oc describe pod/hello-daemonset-cx6md|grep Node Node: openshift-node01.hostname.com/10.14.20.134 $ oc describe pod/hello-daemonset-e3md9|grep Node Node: openshift-node02.hostname.com/10.14.20.137
- DaemonSet の pod テンプレートを更新しても、既存の pod レプリカには影響はありません。
- DaemonSet を削除してから、テンプレートは別のもの、ラベルセレクターは同じものを使用して新規の DaemonSet を作成する場合に、既存の pod レプリカを、ラベルが一致していると認識するため、既存の pod レプリカは更新されず、pod テンプレートで一致しない場合でも新しいレプリカが作成されます。
- ノードのラベルを変更する場合には、DaemonSet は新しいラベルと一致するノードに pod を追加し、新しいラベルと一致しないノードから pod を削除します。
DaemonSet を更新するには、以前のレプリカまたはノードを削除して新規の pod レプリカを強制的に作成します。