CICD-276 · Create ephemeral Kubernetes namespace
Encyclopedia · Advanced Kubernetes operations · All snippets
Previous · CICD-275 · Next · CICD-277
1. Where it fits
- Placement CI run step or authorized lab terminal.
- Prerequisites kubectl, isolated cluster or namespace and installed CRDs when named.
- Platforms kubernetes, local-lab.
- Parameters
PR_NUMBER.
2. Copy the snippet
bash
[[ "${PR_NUMBER:?}" =~ ^[0-9]+$ ]]
kubectl create namespace "preview-$PR_NUMBER" --dry-run=client -o yaml | kubectl apply -f -
kubectl label namespace "preview-$PR_NUMBER" managed-by=preview --overwrite3. How it works
Client dry run renders a candidate object locally so it can be reviewed or piped into a separate apply.
4. Verify the result
Run only from the authorized preview controller. Expect the ownership label after reconciliation.
Validation syntax-validated (Bash parse). Status definitions.