In Kubernetes, what is the difference between soft and hard multi-tenancy, and what do tenants still share when each gets only a namespace?
answer
- trust level decides the model
- a namespace is a scope, not a lock
- RBAC, quota, limits, deny policy, PSA
- kernel and control plane stay common
- CRDs and ClusterRoles are cluster-scoped
basics
~20 sSoft multi-tenancy gives each trusted team a namespace fenced by RBAC, quota and network policy. Hard multi-tenancy assumes hostile tenants and separates clusters or nodes, because namespaces still share the kernel, nodes, control plane and cluster-scoped objects.
solid answer
~40 sA namespace is a name scope that policy objects attach to. It enforces nothing by itself. **Soft multi-tenancy** assumes tenants are mostly trusted teams, and fences each namespace with RBAC, a `ResourceQuota`, a `LimitRange`, a default-deny `NetworkPolicy` and Pod Security Admission labels. That stops accidents and noisy neighbours. **Hard multi-tenancy** assumes a tenant may be hostile, so the boundary has to survive a container escape or API abuse. That means a cluster per tenant, or at least dedicated nodes. Inside one cluster every tenant still shares the node kernel, the nodes and kubelets, the API server and etcd, cluster-scoped objects such as CRDs, ClusterRoles and StorageClasses, and cluster DNS. The choice depends on who writes the code that runs, not on how many teams there are.
go deeper
Remember that a namespace groups names and is not a wall; tenants still share nodes and the cluster itself.
Explain the soft bundle (RBAC, ResourceQuota, LimitRange, default-deny NetworkPolicy, Pod Security labels) and list what stays shared: kernel, nodes, control plane, cluster-scoped objects.
Tie the model to the threat: trusted teams get soft tenancy, untrusted code or input gets dedicated nodes or clusters, and you can say what each still leaks.
Frame the choice as trust level against fleet cost, and explain why isolation strength, not tenant count, should drive the move from namespaces to clusters.
## What a namespace is, and what it is not A **namespace** is a name scope inside one Kubernetes cluster. Two teams can each own a Deployment called `api` in namespaces `invoices` and `payroll` without a collision. Several policy objects are **namespaced** as well, so the namespace is the natural unit to attach them to. A namespace **enforces nothing by itself**. A freshly created namespace has no permission fence beyond what existing bindings grant, no resource ceiling and no network wall. By default a pod in `invoices` can open a connection to any pod in `payroll`, because the pod network is flat. People confuse the *label on the door* with the *lock*. Interviewers probe exactly that confusion. ## Soft multi-tenancy **Soft multi-tenancy** assumes tenants are **mostly trusted**, for example product teams in the same company. The goal is to prevent accidents, privilege creep and noisy neighbours, not to stop a determined attacker. Each tenant gets a namespace plus a standard bundle: - **RBAC**: namespace-scoped bindings, so the team manages only its own objects. - **`ResourceQuota`**: a ceiling on the total requests, limits and object counts the namespace can consume. - **`LimitRange`**: default and bounded requests and limits per container, so unset pods still count against quota sensibly. - **Default-deny `NetworkPolicy`**: traffic is blocked unless explicitly allowed. This works only if the CNI plugin enforces NetworkPolicy. - **Pod Security Admission labels**: `pod-security.kubernetes.io/enforce` on the namespace pins the Pod Security Standard its pods must meet. It is cheap. The tenants share one control plane, one pool of nodes, one upgrade and one set of add-ons. ## Hard multi-tenancy **Hard multi-tenancy** assumes a tenant **may be hostile**: customers running their own code, or a workload such as a PDF-invoice renderer that parses untrusted uploads. The boundary must hold even if a tenant escapes its container or abuses the API. That forces you to separate the things a namespace leaves shared: - a **cluster per tenant**: a separate control plane, nodes and cluster-scoped objects - **dedicated, tainted node pools** per tenant, often with a sandboxed container runtime selected through a `RuntimeClass`. This removes kernel sharing between tenants but keeps the API server shared, so many engineers call it a stronger form of soft tenancy rather than fully hard. ## What stays shared inside one cluster | Shared surface | Why it matters | Does the namespace bundle close it? | |---|---|---| | Node kernel | A container escape or kernel bug reaches every pod on that node | No | | Nodes and kubelet | Disk, PID and network contention. A node's credential can read Secrets of the pods bound to it | Partly: quota caps totals, not who lands beside you | | Cluster-scoped objects | CRDs, ClusterRoles, StorageClasses, PriorityClasses, webhook configurations, Nodes, PersistentVolumes | No | | Control plane | One API server and one etcd. A tenant's list storm or a pile of 612 CRDs costs everyone | No. API Priority and Fairness softens it | | Cluster DNS | Any pod can resolve `<svc>.<ns>.svc.cluster.local` for any namespace | No. NetworkPolicy filters traffic, not name lookups | ## How to choose 1. **Who writes the code that runs?** Your own engineers point to soft. Customers or untrusted input point to hard. 2. **What does one breach cost?** Regulatory or contractual isolation requirements usually settle it. 3. **Do tenants need cluster-scoped control?** Their own CRD versions, admission webhooks or cluster-admin access cannot be granted per namespace. 4. **Can you run the fleet?** Each extra cluster multiplies upgrades, add-ons and idle capacity. ## The interview trap The weak answer is "put each tenant in its own namespace and it is isolated". The strong answer names the bundle that makes a namespace a *soft* boundary, and names the kernel, nodes, control plane and cluster-scoped objects as the reasons it can never be a *hard* one.
- Is a Kubernetes namespace with a default-deny NetworkPolicy enough to host a customer's arbitrary code next to your own?No. The policy blocks pod traffic, but the customer's containers still share the node kernel with yours, so a container escape or kernel bug crosses the boundary. They also share the API server and every cluster-scoped object. Untrusted code needs dedicated nodes, preferably with a sandboxed runtime, or its own cluster.
- Why is dedicated nodes per tenant not always counted as hard multi-tenancy?Dedicated nodes stop tenants sharing a kernel and a kubelet, but all tenants still talk to one API server and one etcd, and they share CRDs, webhooks and other cluster-scoped objects. An API-level abuse or a bad cluster-wide change still reaches everyone, so strict definitions reserve 'hard' for a separate control plane.
- Where does the tenancy decision stop and multi-cluster operation begin?The tenancy decision is choosing whether a tenant gets a namespace, dedicated nodes or its own cluster, and knowing what each isolates. Once the answer is 'many clusters', running that fleet is a separate discipline: provisioning, upgrading, connecting and exporting services across clusters.
Soft tenancy is an office floor with badge-locked rooms: good enough for colleagues, useless if one of them drills through the shared wall. Hard tenancy is a separate building.
saying these in an interview costs you the question
- A namespace on its own is a security boundary between tenants.
- Pods in different namespaces cannot reach each other by default.
- CustomResourceDefinitions can be installed per namespace.
- A NetworkPolicy stops pods resolving other namespaces' Service names.
- Hard multi-tenancy just means stricter ResourceQuota values.
- Separate namespaces give tenants separate kernels.