[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Troubleshoot Policy Controller\n\nThis page shows you how to resolve issues with Policy Controller.\n\nGeneral tips\n------------\n\nThe following section provides general advice for resolving issues with Policy Controller.\n\n### Stop Policy Controller\n\nIf Policy Controller is causing issues in your cluster, you can\n[stop Policy Controller](/kubernetes-engine/enterprise/policy-controller/docs/how-to/stopping-policy-controller) while\nyou investigate the issue.\n\n### Examine metrics\n\n[Examining the Policy Controller metrics](/kubernetes-engine/enterprise/policy-controller/docs/how-to/policy-controller-metrics)\ncan help you to diagnose issues with Policy Controller.\n\n### Verify installation\n\nYou can [verify](/kubernetes-engine/enterprise/policy-controller/docs/how-to/installing-policy-controller#verifying)\nif Policy Controller and the constraint template library were installed\nsuccessfully.\n\n### Detach Policy Controller\n\nIn rare cases, you might need to detach Policy Controller from your clusters.\nThis fully disables management of Policy Controller. Try\n[temporarily stopping Policy Controller](/kubernetes-engine/enterprise/policy-controller/docs/how-to/stopping-policy-controller)\nto see if you can resolve issues before using the `detach` command.\n| **Warning:** This command should only be used in an emergency situation. Don't leave your clusters in a detached state for an extended period of time. If you're experiencing a serious issue with your clusters, reach out to [Google Cloud Support](/support/docs) to report and resolve the issue with the managed control plane so you can reattach your cluster.\n\n1. Detach Policy Controller across your fleet:\n\n gcloud container fleet policycontroller detach\n\n2. Re-attach Policy Controller:\n\n gcloud container fleet policycontroller enable\n\nError creating a constraint template\n------------------------------------\n\nIf you see an error that mentions a `disallowed ref`, confirm you enabled\nreferential constraints. For example, if you use `data.inventory` in a\nconstraint template without [enabling referential constraints](/kubernetes-engine/enterprise/policy-controller/docs/how-to/creating-policy-controller-constraints#referential)\nfirst, the error is similar to the following: \n\n```\nadmission webhook \"validation.gatekeeper.sh\" denied the request: check refs failed on module {templates[\"admission.k8s.gatekeeper.sh\"][\"MyTemplate\"]}: disallowed ref data.inventory...\n```\n\nConstraint not enforced\n-----------------------\n\nThe following section provides troubleshooting guidance if you suspect or know\nyour constraints aren't being enforced.\n\n### Check if your constraint is enforced\n\nIf you're concerned that your constraint is not enforced, you can check the\n`spec.status` of your constraint and the constraint template. To check the\nstatus, run the following command: \n\n kubectl describe \u003cvar translate=\"no\"\u003eCONSTRAINT_TEMPLATE_NAME\u003c/var\u003e \u003cvar translate=\"no\"\u003eCONSTRAINT_NAME\u003c/var\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eCONSTRAINT_TEMPLATE_NAME\u003c/var\u003e: the name of the constraint template that you want to check. For example, `K8sNoExternalServices`.\n- \u003cvar translate=\"no\"\u003eCONSTRAINT_NAME\u003c/var\u003e: the `Name` of the constraint that you want\n to check.\n\n If needed, run `kubectl get constraint` to see which constraint templates and\n constraints are installed on your system.\n\nIn the output of the `kubectl describe` command, take note the values in the\n`metadata.generation` and `status.byPod.observedGeneration` fields. In the\nfollowing example these values are bolded: \n\n Name: no-internet-services\n Namespace:\n API Version: constraints.gatekeeper.sh/v1beta1\n Kind: K8sNoExternalServices\n Metadata:\n Creation Timestamp: 2021-12-03T19:00:06Z\n Generation: 1\n Managed Fields:\n API Version: constraints.gatekeeper.sh/v1beta1\n Fields Type: FieldsV1\n fieldsV1:\n f:metadata:\n f:annotations:\n f:config.k8s.io/owning-inventory:\n f:configmanagement.gke.io/cluster-name:\n f:configmanagement.gke.io/managed:\n f:configmanagement.gke.io/source-path:\n f:configmanagement.gke.io/token:\n f:configsync.gke.io/declared-fields:\n f:configsync.gke.io/git-context:\n f:configsync.gke.io/manager:\n f:configsync.gke.io/resource-id:\n f:labels:\n f:app.kubernetes.io/managed-by:\n f:configsync.gke.io/declared-version:\n f:spec:\n f:parameters:\n f:internalCIDRs:\n Manager: configsync.gke.io\n Operation: Apply\n Time: 2022-02-15T17:13:20Z\n API Version: constraints.gatekeeper.sh/v1beta1\n Fields Type: FieldsV1\n fieldsV1:\n f:status:\n Manager: gatekeeper\n Operation: Update\n Time: 2021-12-03T19:00:08Z\n Resource Version: 41460953\n UID: ac80849d-a644-4c5c-8787-f73e90b2c988\n Spec:\n Parameters:\n Internal CID Rs:\n Status:\n Audit Timestamp: 2022-02-15T17:21:51Z\n By Pod:\n Constraint UID: ac80849d-a644-4c5c-8787-f73e90b2c988\n Enforced: true\n Id: gatekeeper-audit-5d4d474f95-746x4\n Observed Generation: 1\n Operations:\n audit\n status\n Constraint UID: ac80849d-a644-4c5c-8787-f73e90b2c988\n Enforced: true\n Id: gatekeeper-controller-manager-76d777ddb8-g24dh\n Observed Generation: 1\n Operations:\n webhook\n Total Violations: 0\n Events: \u003cnone\u003e\n\nIf you see every Policy Controller Pod with an `observedGeneration` value equal to\nthe `metadata.generation` value (which is the case in the preceding example),\nthen your constraint is likely enforced. However, if these values match, but you\nare still experiencing problems with your constraint being enforced, see the\n[following section](#not-enforced-audit) for tips. If you notice that there are\nonly some values that match, or some Pods aren't listed, then the status of your\nconstraint is unknown. The constraint might be inconsistently enforced across\nPolicy Controller's Pods, or not enforced at all. If there are no values that\nmatch, then your constraint is not enforced.\n\n### Constraint not enforced, but audit results reported\n\nIf the `observedGeneration` check described in the preceding section had\nmatching values and there are\n[audit results](/kubernetes-engine/enterprise/policy-controller/docs/how-to/auditing-constraints) reported on the\nconstraint that show expected violations (for pre-existing objects, not for\ninbound requests), but the constraint is still not enforced then the problem is\nlikely to do with the webhook. The webhook might be experiencing one of the\nfollowing issues:\n\n- The Policy Controller webhook Pod might not be operational. [Kubernetes debugging techniques](https://kubernetes.io/docs/tasks/debug/debug-application/debug-pods/) might help you to resolve issues with the webhook Pod.\n- There could be a firewall between the API server and the webhook service. Refer to your firewall provider's documentation for details on how to fix the firewall.\n\n### Referential constraint not enforced\n\nIf your constraint is a\n[referential constraint](/kubernetes-engine/enterprise/policy-controller/docs/how-to/creating-policy-controller-constraints#referential),\nmake sure the necessary resources are being cached. For details on how to cache\nresources, see\n[Configure Policy Controller for referential constraints](/kubernetes-engine/enterprise/policy-controller/docs/how-to/creating-policy-controller-constraints#gatekeeper-config).\n\n### Check the constraint template syntax\n\nIf you [wrote your own constraint template](/kubernetes-engine/enterprise/policy-controller/docs/how-to/write-custom-constraint-templates),\nand it's not enforced, there might be an error in the constraint template syntax.\n\nYou can review the template by using the following command: \n\n kubectl describe constrainttemplate \u003cvar translate=\"no\"\u003eCONSTRAINT_TEMPLATE_NAME\u003c/var\u003e\n\nReplace \u003cvar translate=\"no\"\u003eCONSTRAINT_TEMPLATE_NAME\u003c/var\u003e with the name of the\ntemplate that you want to investigate. Errors should be reported in the\n`status` field.\n\nWhat's next\n-----------\n\n- If you can't find a solution to your problem in the documentation, see [Get\n support](/kubernetes-engine/enterprise/policy-controller/docs/get-support-policy-controller)\n for further help, including advice on the following topics:\n\n - Opening a support case by contacting [Cloud Customer Care](/support-hub)\n\n - Opening bugs or feature requests by using the\n [public Google Cloud issue tracker](https://issuetracker.google.com/issues/new?component=1161523)\n or\n [opening a public bug for Gatekeeper](https://github.com/open-policy-agent/gatekeeper/issues)\n on GitHub."]]