1
---
2
name: gke-multitenancy
3
description: >-
4
Plans and configures multi-tenancy on GKE. Covers namespace isolation, RBAC
5
planning for teams, resource quotas, LimitRanges, network isolation, and
6
cost allocation. Use when designing GKE multi-tenancy, configuring GKE
7
namespaces, setting up resource quotas, or isolating GKE teams. Don't use
8
for single-tenant cluster configuration or general deployment instructions
9
(use gke-basics or gke-app-onboarding instead).
10
metadata:
11
version: "1.0.2"
12
category: Containers
13
---
14
15
# GKE Multi-Tenancy
16
17
This reference covers enterprise multi-tenancy patterns on GKE, including
18
namespace isolation, RBAC planning, resource quotas, and network segmentation.
19
20
> **MCP Tools:** `apply_k8s_manifest`, `get_k8s_resource`, `check_k8s_auth`,
21
> `describe_k8s_resource`, `delete_k8s_resource`
22
23
## Attribution
24
25
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
26
MUST read [Usage Attribution](references/attribution.md). For commands executed
27
directly in the terminal (never in generated scripts, Terraform, or user code),
28
prefix `gcloud` with
29
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-multitenancy)"`
30
and append `agent-skills/1.0 (skill:gke-multitenancy)` to `User-Agent` headers.
31
32
## When to Use
33
34
- Multiple teams sharing a single GKE cluster
35
- Isolating workloads by environment (dev/staging/prod) within one cluster
36
- Implementing least-privilege access control
37
- Cost allocation across teams or projects
38
39
## Multi-Tenancy Models
40
41
| Model | Isolation | Complexity | Cost |
42
| ----------------------------- | ------------ | ---------- | -------------- |
43
| **Namespace-per-team** | Soft (RBAC + | Low | Lowest (shared |
44
: : Network : : cluster) :
45
: : Policy) : : :
46
| **Namespace-per-environment** | Soft | Low | Low |
47
| **Node pool-per-team** | Medium | Medium | Medium |
48
: : (dedicated : : :
49
: : compute) : : :
50
| **Cluster-per-team** | Hard (full | High | Highest |
51
: : isolation) : : :
52
53
> **Golden path recommendation**: Start with namespace-per-team for cost
54
> efficiency. Escalate to stronger isolation only when compliance requires it.
55
56
## Namespace Isolation Setup
57
58
### 1. Create Namespaces
59
60
```bash
61
kubectl create namespace team-a
62
kubectl create namespace team-b
63
kubectl label namespace team-a team=a
64
kubectl label namespace team-b team=b
65
```
66
67
### 2. RBAC Configuration
68
69
**Principle**: Grant minimal permissions per namespace. Never bind to
70
`system:authenticated`.
71
72
```yaml
73
# Namespace-scoped role for a team
74
apiVersion: rbac.authorization.k8s.io/v1
75
kind: Role
76
metadata:
77
name: team-a-developer
78
namespace: team-a
79
rules:
80
- apiGroups: ["", "apps", "batch"]
81
resources: ["pods", "deployments", "services", "configmaps", "jobs"]
82
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
83
---
84
apiVersion: rbac.authorization.k8s.io/v1
85
kind: RoleBinding
86
metadata:
87
name: team-a-developers
88
namespace: team-a
89
subjects:
90
- kind: Group
91
name: "team-a@example.com" # Google Group
92
apiGroup: rbac.authorization.k8s.io
93
roleRef:
94
kind: Role
95
name: team-a-developer
96
apiGroup: rbac.authorization.k8s.io
97
```
98
99
**RBAC best practices:** Use Google Groups for subject bindings. Prefer
100
namespace-scoped Roles over ClusterRoles. See the `gke-platform-security` skill
101
for full RBAC hardening guidance.
102
103
### 3. Resource Quotas
104
105
Prevent any single team from consuming all cluster resources:
106
107
```yaml
108
apiVersion: v1
109
kind: ResourceQuota
110
metadata:
111
name: team-a-quota
112
namespace: team-a
113
spec:
114
hard:
115
requests.cpu: "10"
116
requests.memory: "20Gi"
117
limits.cpu: "20"
118
limits.memory: "40Gi"
119
pods: "50"
120
services: "10"
121
persistentvolumeclaims: "10"
122
```
123
124
### 4. LimitRanges
125
126
Set default and maximum resource constraints per container:
127
128
```yaml
129
apiVersion: v1
130
kind: LimitRange
131
metadata:
132
name: team-a-limits
133
namespace: team-a
134
spec:
135
limits:
136
- type: Container
137
default:
138
cpu: "500m"
139
memory: "512Mi"
140
defaultRequest:
141
cpu: "100m"
142
memory: "128Mi"
143
max:
144
cpu: "4"
145
memory: "8Gi"
146
```
147
148
> [!IMPORTANT] **Mandatory Defaults**: When defining `min` or `max` limits in a
149
> `LimitRange`, you **must** also define corresponding `default` and
150
> `defaultRequest` values. If you set a `min` or `max` without defaults, any pod
151
> deployed without explicit resource requests/limits will be rejected by the
152
> admission controller.
153
154
### 5. Network Isolation
155
156
Apply default-deny per namespace (see the `gke-workload-security` skill), then
157
allow intra-team traffic:
158
159
```yaml
160
# Allow same-namespace pods to talk + DNS
161
apiVersion: networking.k8s.io/v1
162
kind: NetworkPolicy
163
metadata:
164
name: allow-same-namespace
165
namespace: team-a
166
spec:
167
podSelector: {}
168
ingress:
169
- from:
170
- podSelector: {}
171
egress:
172
- to:
173
- podSelector: {}
174
- to: # Allow DNS
175
- namespaceSelector: {}
176
podSelector:
177
matchLabels:
178
k8s-app: kube-dns
179
ports:
180
- protocol: UDP
181
port: 53
182
```
183
184
## Cost Allocation
185
186
### Labels for Cost Attribution
187
188
```bash
189
# Label namespaces for billing
190
kubectl label namespace team-a cost-center=engineering
191
kubectl label namespace team-b cost-center=data-science
192
```
193
194
### GKE Cost Allocation
195
196
Enable GKE cost allocation to break down costs by namespace and label:
197
198
```bash
199
gcloud container clusters update <CLUSTER_NAME> --region <REGION> \
200
--enable-cost-allocation
201
```
202
203
View in the Cloud Billing Reports page or query the Cloud Billing detailed usage
204
cost export in BigQuery.
205