15.2. Pod の Preset の作成
以下の例は、Pod の Preset を作成し、使用する方法を示しています。
- 受付コントローラーの追加
- 管理者は /etc/origin/master/master-config.yaml ファイルをチェックして、Pod の Preset 受付コントローラープラグインが存在することを確認できます。受付コントローラーが存在しない場合は、以下を使用してプラグインを追加します。
admissionConfig:
pluginConfig:
PodPreset:
configuration:
kind: DefaultAdmissionConfig
apiVersion: v1
disable: false
次に OpenShift Container Platform サービスを再起動します。
# systemctl restart atomic-openshift-master-api atomic-openshift-master-controllers
- Pod の Preset の作成
-
管理者または開発者は、
settings.k8s.io/v1alpha1API、挿入する情報、および Pod に一致するラベルセレクターを使用して Pod の Preset を作成します。
kind: PodPreset
apiVersion: settings.k8s.io/v1alpha1
metadata:
name: allow-database
spec:
selector:
matchLabels:
role: frontend
env:
- name: DB_PORT
value: "6379"
volumeMounts:
- mountPath: /cache
name: cache-volume
volumes:
- name: cache-volume
emptyDir: {}
- Pod の作成
開発者は Pod の Preset のラベルセレクターに一致するラベルを使って Pod を作成します。
Pod の Preset のラベルセレクターに一致するラベルで標準的な Pod 仕様を作成します。
apiVersion: v1 kind: Pod metadata: name: website labels: app: website role: frontend spec: containers: - name: website image: ecorp/website ports: - containerPort: 80Pod を作成します。
$ oc create -f pod.yaml作成後に Pod 仕様をチェックします。
$ oc get pod website -o yaml apiVersion: v1 kind: Pod metadata: name: website labels: app: website role: frontend annotations: podpreset.admission.kubernetes.io/allow-database: "resource version"1 spec: containers: - name: website image: ecorp/website volumeMounts:2 - mountPath: /cache name: cache-volume ports: - containerPort: 80 env:3 - name: DB_PORT value: "6379" volumes: - name: cache-volume emptyDir: {}