> For the complete documentation index, see [llms.txt](https://docs.portainer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.portainer.io/admin/environments/policies/kubernetes-policies/kubernetes-security-policy.md).

# Create a Kubernetes security policy

Define a policy by specifying security constraints for Kubernetes clusters.

To create a Kubernetes security policy, in the menu, under **Environment-related**, select **Policies** then select **Create policy**. From the policy type list, go to **Kubernetes** > **Security**, select either a predefined template or the **Custom** policy, then select **Continue** to start configuring the policy.

| Field/Option                                             | Overview                                                                                                                                                                                                                                                                                                                                                                    |
| -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Name                                                     | Define a name for this policy.                                                                                                                                                                                                                                                                                                                                              |
| Environment groups                                       | <p>Select one or more Kubernetes environment <a href="/pages/-MgcuVpHfggt_wDn_a0N">groups</a> from the dropdown menu.<br>If the selected group is already included in an existing policy, a warning icon will appear next to the group name.</p>                                                                                                                            |
| Restrict access to the default namespace                 | When this option is enabled, the default namespace behaves like any other standard namespace. Access is restricted to admin users and to users who have been explicitly granted permission.                                                                                                                                                                                 |
| Restrict secret contents access for non-admins (UI only) | By default, users are able to view and edit Kubernetes secrets within the Portainer UI. Enabling this option disallows all non-admin users from doing so. Note that due to limitations within Kubernetes itself this only applies to the Portainer UI and does not prevent users from doing so through the command line or API.                                             |
| Enable pod security constraints                          | <p>Pod security constraints can be used to define under what conditions workloads can run. To set these constraints, toggle this option on, then toggle and configure the features you require.<br>More information on each pod security constraint option can be found in the Kubernetes <a href="/pages/MgJUuNB8QGTUai2EdTHh">security constraints</a> documentation.</p> |

<figure><img src="/files/7qbZ4cLXvnVzIGYSQJif" alt=""><figcaption></figcaption></figure>

When you have completed the form, click **Create policy.** A confirmation screen displays the changes being made and any existing policy that will be replaced. Click **Confirm** to acknowledge the changes and create the policy.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.portainer.io/admin/environments/policies/kubernetes-policies/kubernetes-security-policy.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
