kubectl で Policy Controller を手動でインストールする
次の手順では、kubectl
コマンドを使用して Policy Controller をインストールする方法について説明します。Google Cloud Console または Google Cloud CLI を使用する場合は、Policy Controller のインストールをご覧ください。
このページで説明する kubectl
コマンドを使用して Policy Controller を構成する場合は、後で Google Cloud Console または Google Cloud CLI を使用して構成を変更できます。ただし、Cloud Console または gcloud CLI を使用して構成を変更すると、kubectl
コマンドを使用して構成を変更できなくなります。
デフォルトでは、Policy Controller は一般的なポリシータイプの制約テンプレートのライブラリをインストールします。制約テンプレートのインストールをスキップするには、マニフェストの templateLibraryInstalled
で始まる行のコメント化を解除します。
新しい
config-management.yaml
ファイルを作成するか、既存のファイルを更新して、構成を準備します。次の YAML ファイルを
config-management.yaml
ファイルにコピーします。# config-management.yaml apiVersion: configmanagement.gke.io/v1 kind: ConfigManagement metadata: name: config-management spec: # Set to true to install and enable Policy Controller policyController: enabled: true # Uncomment to prevent the template library from being installed # templateLibraryInstalled: false # Uncomment to enable support for referential constraints # referentialRulesEnabled: true # Uncomment to disable audit, adjust value to set audit interval # auditIntervalSeconds: 0 # Uncomment to log all denies and dryrun failures # logDeniesEnabled: true # Uncomment to exempt namespaces # exemptableNamespaces: ["namespace-name"] # ...other fields...
spec.policyController
フィールドを追加し、enabled
の値をtrue
に設定する必要があります。他の Policy Controller 機能を有効にすることもできます。しかし、参照制約のサポートは、デフォルトで無効になっています。有効にする前に、結果整合性に関する注意事項を必ず理解してください。kubectl apply
を使用して構成を適用します。kubectl apply -f config-management.yaml
Policy Controller の確認
Policy Controller が正しくインストールされている場合、その Pod が実行されます。Pod が使用可能になるまでに Pod が数回再起動される場合があります。
Policy Controller Pod は gatekeeper-system
名前空間で実行されるため、次のコマンドを実行してステータスを確認できます。
kubectl get pods -n gatekeeper-system
出力は次の例のようになります。
NAME READY STATUS RESTARTS AGE gatekeeper-controller-manager-0 1/1 Running 1 53s
Policy Controller のアンインストール
Policy Controller をアンインストールするには、config-management.yaml
ファイルで Anthos Config Management の構成を編集し、policyController.enabled
を false
に設定します。Anthos Config Management が policycontroller.configmanagement.gke.io
ファイナライザを削除すると、アンインストールは完了です。
Anthos Config Management を完全にアンインストールする場合は、Config Management Operator の削除をご覧ください。