Skip to content

Fix Rancher Project/Namespace – Resources Not Isolated

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Fix Rancher Project/Namespace. We cover key concepts, practical examples, and best practices.

You create a Project in Rancher, assign a resource quota, and move namespaces into it. But users outside the project can still deploy workloads into those namespaces. The resource quota shows 0 usage even when pods are running.

Wrong ❌

Project: Team-A
  Namespaces: team-a-dev, team-a-staging
  Resource Quota: CPU 4, Memory 8 Gi

A user from `Team-B` deploys a pod into `team-a-dev`:

```bash
kubectl run nginx --image=nginx -n team-a-dev
# → pod created successfully

The quota isn't enforced either. `kubectl describe quota -n team-a-dev` shows:

Resource  Used  Hard
cpu       0     4
memory    0     8Gi

Usage stuck at 0.

## Right ✅

**Ensure the project has a Resource Quota:**

1. **Clusters → your-cluster → Projects/Namespaces**
2. Click **Team-A** project → **Edit Config**
3. **Resource Quotas tab:**
   - **Namespace Default Resource Quota:**
     - CPU: `2` request, `4` limit
     - Memory: `4 Gi` request, `8 Gi` limit
4. **Namespace Default Limit Range:**
   - CPU: min `50m`, max `2`
   - Memory: min `128 Mi`, max `4 Gi`
5. Click **Save**

**Move namespace into project if not assigned:**

```yaml
apiVersion: v1
kind: Namespace
metadata:
  name: team-a-dev
  annotations:
    field.cattle.io/projectId: <project-id>

To find the project ID:

```bash
kubectl get projects -n cattle-project-p-xxxxx
# → p-xxxxx

Annotate the namespace:

```bash
kubectl annotate namespace team-a-dev field.cattle.io/projectId=p-xxxxx

**Verify RBAC isolation:**

Rancher's **Project** role binds to a `RoleBinding` in each project namespace. Ensure `Team-B` doesn't have a role binding in `team-a-dev`:

```bash
kubectl get rolebindings -n team-a-dev
# Should not include Team-B members

**Test quota enforcement:**

```bash
kubectl run nginx --image=nginx -n team-a-dev
# → Error: forbidden: exceeded quota: team-a-dev-quota

## Root Cause

Namespaces are only isolated under a project if they carry the `field.cattle.io/projectId` annotation. Without it, any authenticated user can deploy into them. Resource quotas must be defined at the project level and cascade to child namespaces.

## Prevention

- Always create namespaces **through Rancher's UI** or annotate them with the project ID.
- Use **Project Role Templates** to control who can deploy within a project's namespaces.
- Set **Namespace Default Resource Quota** when creating the project — not after.
- Audit project membership when users change teams.


## Common Mistakes with project namespace

1. **Using `head` and `tail` instead of pattern matching, causing runtime errors on empty lists**
2. **Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks**
3. **Using `return` to exit a function early instead of wrapping a pure value in the monad**

These mistakes appear frequently in real-world RANCHER code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

## Practice Exercise

**Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.**

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

## FAQ

<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Can a namespace belong to multiple projects?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: No — a namespace belongs to exactly one project. Move it by changing the annotation.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Why does my quota show "Used: 0" even after deploying?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: The namespace may not be associated with the project. Check the <code>field.cattle.io/projectId</code> annotation.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: How do I give a user access to a single project?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Add the user to the project with a <strong>Project Member</strong> role (e.g. &quot;Project Owner&quot; or &quot;Project Member&quot;).</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Can I set different quotas per namespace within a project?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Yes — each namespace inherits the project's <strong>Default Quota</strong>, but you can override it in the namespace YAML.</p>
</div></details>

---

*Project management is covered in the [DodaTech Rancher Multi-Tenancy course](https://dodatech.com/courses/rancher).*

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro