Skip to main content
skill CX Codex

k8s-policy — Claude Code skill: what it does, how to install

The k8s-policy skill manages Kubernetes policies with Kyverno and Gatekeeper. Use it to validate resources, inspect violations, and audit compliance.

MIT-0 1 installs ★ 976 updated 2026-10-22

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add rohitg00/kubectl-mcp-server --skill k8s-policy -a claude-code
Open on GitHub

What k8s-policy does

k8s-policy provides a workflow for Kubernetes policy tasks through kubectl-mcp-server. It detects the policy engine, lists policies or constraints, retrieves their details, and checks policy reports for violations. The skill covers both Kyverno and Gatekeeper with OPA.

It can apply policy manifests with kubectl_apply and supports checks before enforcement by using audit-oriented validation. Kyverno must be installed for Kyverno operations, and Gatekeeper must be installed for Gatekeeper operations. The policy toolset is required: start kubectl-mcp-server with --toolsets default,policy or set MCP_TOOLSETS=default,policy, otherwise these tools will not be available.

What it helps with

  • detect the Kubernetes policy engine in use
  • list Kyverno policies and Gatekeeper constraints
  • inspect policy reports for violations
  • retrieve details for a specific policy
  • apply a policy manifest with kubectl_apply

Example prompts for the agent

  • Detect the installed policy engine and list the Kubernetes policies.
  • Audit the policies in the default namespace and show any violations.
  • Create a Kyverno policy that requires the app label on Pods.

How to install k8s-policy

1Skills CLI (Vercel)

npx skills add rohitg00/kubectl-mcp-server --skill k8s-policy -a claude-code

2Manually: put the files in place

~/.claude/skills/k8s-policy/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/k8s-policy/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about k8s-policy

How do I install k8s-policy in Claude Code?

Run npx skills add rohitg00/kubectl-mcp-server --skill k8s-policy -a claude-code. The skill file will be placed at ~/.claude/skills/k8s-policy/SKILL.md.

What does k8s-policy do?

It guides Kubernetes policy work with Kyverno and Gatekeeper: detecting the engine, listing policies or constraints, reading violations, and applying policy manifests.

What does k8s-policy require to work?

Start kubectl-mcp-server with the policy toolset by using --toolsets default,policy or MCP_TOOLSETS=default,policy. The matching Kyverno or Gatekeeper installation is also required for its tools.

Source text

SKILL.md · MIT-0
---
name: k8s-policy
description: Kubernetes policy management with Kyverno and Gatekeeper. Use when enforcing security policies, validating resources, or auditing policy compliance.
license: MIT-0
metadata:
  author: rohitg00
  version: "2.0.0"
  tools: 5
  category: security
---

# Kubernetes Policy Management

Manage policies using kubectl-mcp-server's Kyverno and Gatekeeper tools.

> Requires the `policy` toolset: start kubectl-mcp-server with `--toolsets default,policy` (or `MCP_TOOLSETS=default,policy`). For deep work, the project-maintained MCP servers may fit better: Kyverno: https://github.com/nirmata/kyverno-mcp.

## When to Apply

Use this skill when:
- User mentions: "Kyverno", "Gatekeeper", "OPA", "policy", "compliance"
- Operations: enforcing policies, checking violations, policy audit
- Keywords: "require labels", "block privileged", "validate", "enforce"

## Priority Rules

| Priority | Rule | Impact | Tools |
|----------|------|--------|-------|
| 1 | Detect policy engine first | CRITICAL | `detect_ecosystem`, `detect_ecosystem` |
| 2 | Use Audit mode before Enforce | HIGH | validationFailureAction |
| 3 | Check policy reports for violations | HIGH | `get_policy_violations` |
| 4 | Review constraint templates | MEDIUM | `get_policy_list` |

## Quick Reference

| Task | Tool | Example |
|------|------|---------|
| List Kyverno cluster policies | `get_policy_list` | `get_policy_list()` |
| Get Kyverno policy | `get_policy` | `get_policy(name)` |
| List Gatekeeper constraints | `get_policy_list` | `get_policy_list()` |
| Get constraint | `get_policy` | `get_policy(kind, name)` |

## Kyverno

### Detect Installation

```python
detect_ecosystem()
```

### List Policies

```python
get_policy_list()

get_policy_list(namespace="default")
```

### Get Policy Details

```python
get_policy(name="require-labels")
get_policy(name="require-resources", namespace="default")
```

### Policy Reports

```python
get_policy_violations()

get_policy_violations(namespace="default")
```

### Common Kyverno Policies

```python
kubectl_apply(manifest="""
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: require-labels
spec:
  validationFailureAction: Enforce
  rules:
  - name: require-app-label
    match:
      resources:
        kinds:
        - Pod
    validate:
      message: "Label 'app' is required"
      pattern:
        metadata:
          labels:
            app: "?*"
""")

kubectl_apply(manifest="""
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: require-limits
spec:
  validationFailureAction: Enforce
  rules:
  - name: require-cpu-memory
    match:
      resources:
        kinds:
        - Pod
    validate:
      message: "CPU and memory limits required"
      pattern:
        spec:
          containers:
          - resources:
              limits:
                cpu: "?*"
                memory: "?*"
""")
```

## Gatekeeper (OPA)

### Detect Installation

```python
detect_ecosystem()
```

### List Constraints

```python
get_policy_list()

get_policy_list()
```

### Get Constraint Details

```python
get_policy(
    kind="K8sRequiredLabels",
    name="require-app-label"
)

get_policy(name="k8srequiredlabels")
```

### Common Gatekeeper Policies

```python
kubectl_apply(manifest="""
apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
  name: k8srequiredlabels
spec:
  crd:
    spec:
      names:
        kind: K8sRequiredLabels
      validation:
        openAPIV3Schema:
          type: object
          properties:
            labels:
              type: array
              items:
                type: string
  targets:
  - target: admission.k8s.gatekeeper.sh
    rego: |
      package k8srequiredlabels
      violation[{"msg": msg}] {
        provided := {label | input.review.object.metadata.labels[label]}
        required := {label | label := input.parameters.labels[_]}
        missing := required - provided
        count(missing) > 0
        msg := sprintf("Missing labels: %v", [missing])
      }
""")

kubectl_apply(manifest="""
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredLabels
metadata:
  name: require-app-label
spec:
  match:
    kinds:
    - apiGroups: [""]
      kinds: ["Pod"]
  parameters:
    labels: ["app", "env"]
""")
```

## Policy Audit Workflow

```python
detect_ecosystem()
get_policy_list()
get_policy_violations()
```

## Prerequisites

- **Kyverno**: Required for Kyverno tools
  ```bash
  kubectl create -f https://github.com/kyverno/kyverno/releases/latest/download/install.yaml
  ```
- **Gatekeeper**: Required for Gatekeeper tools
  ```bash
  kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper/master/deploy/gatekeeper.yaml
  ```

## Related Skills

- [k8s-security](../k8s-security/SKILL.md) - RBAC and security
- [k8s-operations](../k8s-operations/SKILL.md) - Apply policies

© rohitg00 · MIT-0 · rohitg00/kubectl-mcp-server

Similar skills

All skills for Security →

From the same set5

Project sponsors

Companies that keep this analytics open