> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kguardian.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# gen networkpolicy

> Generate Kubernetes or Cilium Network Policies

## Synopsis

Generate Network Policies based on observed pod traffic.

```bash theme={null}
kubectl kguardian gen networkpolicy [POD_NAME] [flags]
kubectl kguardian gen netpol [POD_NAME] [flags]  # Alias
```

## Flags

| Flag                   | Type   | Description                           | Default            |
| ---------------------- | ------ | ------------------------------------- | ------------------ |
| `-n, --namespace`      | string | Namespace of the pod                  | Current namespace  |
| `-a, --all`            | bool   | Generate for all pods in namespace    | `false`            |
| `-A, --all-namespaces` | bool   | Generate for all pods cluster-wide    | `false`            |
| `-t, --type`           | string | Policy type: `kubernetes` or `cilium` | `kubernetes`       |
| `--output-dir`         | string | Directory to save policies            | `network-policies` |
| `--dry-run`            | bool   | Generate without applying             | `true`             |

## Examples

```bash theme={null}
# Single pod
kubectl kguardian gen networkpolicy my-app -n prod --output-dir ./policies

# All pods in namespace
kubectl kguardian gen netpol --all -n staging --output-dir ./staging-policies

# Cilium policies cluster-wide
kubectl kguardian gen netpol -A --type cilium --output-dir ./cilium

# Generate and apply
kubectl kguardian gen netpol my-app --dry-run=false
```

***

See [Generating Network Policies](/guides/generating-network-policies) for detailed usage.
