0
# Core API Resources
1
2
Management of fundamental Kubernetes resources including pods, services, namespaces, config maps, secrets, and persistent volumes. These resources form the basic building blocks for all Kubernetes applications and provide essential cluster functionality.
3
4
## Capabilities
5
6
### Pod Management
7
8
Create, read, update, and delete pods - the smallest deployable units in Kubernetes that contain one or more containers.
9
10
```python { .api }
11
class CoreV1Api:
12
def create_namespaced_pod(
13
self,
14
namespace: str,
15
body: V1Pod,
16
dry_run: str = None,
17
field_manager: str = None,
18
pretty: str = None
19
) -> V1Pod:
20
"""Create a pod in specified namespace."""
21
22
def list_namespaced_pod(
23
self,
24
namespace: str,
25
pretty: str = None,
26
allow_watch_bookmarks: bool = None,
27
continue_: str = None,
28
field_selector: str = None,
29
label_selector: str = None,
30
limit: int = None,
31
resource_version: str = None,
32
timeout_seconds: int = None,
33
watch: bool = None
34
) -> V1PodList:
35
"""List pods in specified namespace."""
36
37
def read_namespaced_pod(
38
self,
39
name: str,
40
namespace: str,
41
pretty: str = None
42
) -> V1Pod:
43
"""Read specified pod."""
44
45
def patch_namespaced_pod(
46
self,
47
name: str,
48
namespace: str,
49
body: object,
50
dry_run: str = None,
51
field_manager: str = None,
52
force: bool = None,
53
pretty: str = None
54
) -> V1Pod:
55
"""Patch specified pod."""
56
57
def delete_namespaced_pod(
58
self,
59
name: str,
60
namespace: str,
61
body: V1DeleteOptions = None,
62
dry_run: str = None,
63
grace_period_seconds: int = None,
64
orphan_dependents: bool = None,
65
propagation_policy: str = None,
66
pretty: str = None
67
) -> V1Status:
68
"""Delete specified pod."""
69
70
def create_namespaced_pod_eviction(
71
self,
72
name: str,
73
namespace: str,
74
body: V1Eviction,
75
dry_run: str = None,
76
field_manager: str = None,
77
pretty: str = None
78
) -> V1Eviction:
79
"""Evict a pod using the eviction API."""
80
81
def create_namespaced_pod_binding(
82
self,
83
name: str,
84
namespace: str,
85
body: V1Binding,
86
dry_run: str = None,
87
field_manager: str = None,
88
pretty: str = None
89
) -> V1Binding:
90
"""Bind a pod to a node."""
91
92
def connect_get_namespaced_pod_proxy(
93
self,
94
name: str,
95
namespace: str,
96
path: str = None,
97
**kwargs
98
) -> str:
99
"""Connect to proxy of specified pod."""
100
```
101
102
### Service Management
103
104
Manage services for exposing applications running on pods to network traffic.
105
106
```python { .api }
107
class CoreV1Api:
108
def create_namespaced_service(
109
self,
110
namespace: str,
111
body: V1Service,
112
dry_run: str = None,
113
field_manager: str = None,
114
pretty: str = None
115
) -> V1Service:
116
"""Create a service in specified namespace."""
117
118
def list_namespaced_service(
119
self,
120
namespace: str,
121
pretty: str = None,
122
allow_watch_bookmarks: bool = None,
123
continue_: str = None,
124
field_selector: str = None,
125
label_selector: str = None,
126
limit: int = None,
127
resource_version: str = None,
128
timeout_seconds: int = None,
129
watch: bool = None
130
) -> V1ServiceList:
131
"""List services in specified namespace."""
132
133
def read_namespaced_service(
134
self,
135
name: str,
136
namespace: str,
137
pretty: str = None
138
) -> V1Service:
139
"""Read specified service."""
140
```
141
142
### Namespace Management
143
144
Create and manage namespaces for organizing and isolating cluster resources.
145
146
```python { .api }
147
class CoreV1Api:
148
def create_namespace(
149
self,
150
body: V1Namespace,
151
dry_run: str = None,
152
field_manager: str = None,
153
pretty: str = None
154
) -> V1Namespace:
155
"""Create a namespace."""
156
157
def list_namespace(
158
self,
159
pretty: str = None,
160
allow_watch_bookmarks: bool = None,
161
continue_: str = None,
162
field_selector: str = None,
163
label_selector: str = None,
164
limit: int = None,
165
resource_version: str = None,
166
timeout_seconds: int = None,
167
watch: bool = None
168
) -> V1NamespaceList:
169
"""List namespaces."""
170
171
def delete_namespace(
172
self,
173
name: str,
174
body: V1DeleteOptions = None,
175
dry_run: str = None,
176
grace_period_seconds: int = None,
177
orphan_dependents: bool = None,
178
propagation_policy: str = None,
179
pretty: str = None
180
) -> V1Status:
181
"""Delete specified namespace."""
182
```
183
184
### ConfigMap Management
185
186
Manage configuration data stored as key-value pairs that can be consumed by pods.
187
188
```python { .api }
189
class CoreV1Api:
190
def create_namespaced_config_map(
191
self,
192
namespace: str,
193
body: V1ConfigMap,
194
dry_run: str = None,
195
field_manager: str = None,
196
pretty: str = None
197
) -> V1ConfigMap:
198
"""Create a config map in specified namespace."""
199
200
def list_namespaced_config_map(
201
self,
202
namespace: str,
203
pretty: str = None,
204
allow_watch_bookmarks: bool = None,
205
continue_: str = None,
206
field_selector: str = None,
207
label_selector: str = None,
208
limit: int = None,
209
resource_version: str = None,
210
timeout_seconds: int = None,
211
watch: bool = None
212
) -> V1ConfigMapList:
213
"""List config maps in specified namespace."""
214
```
215
216
### Secret Management
217
218
Manage sensitive data like passwords, tokens, and keys stored securely in the cluster.
219
220
```python { .api }
221
class CoreV1Api:
222
def create_namespaced_secret(
223
self,
224
namespace: str,
225
body: V1Secret,
226
dry_run: str = None,
227
field_manager: str = None,
228
pretty: str = None
229
) -> V1Secret:
230
"""Create a secret in specified namespace."""
231
232
def list_namespaced_secret(
233
self,
234
namespace: str,
235
pretty: str = None,
236
allow_watch_bookmarks: bool = None,
237
continue_: str = None,
238
field_selector: str = None,
239
label_selector: str = None,
240
limit: int = None,
241
resource_version: str = None,
242
timeout_seconds: int = None,
243
watch: bool = None
244
) -> V1SecretList:
245
"""List secrets in specified namespace."""
246
```
247
248
### Persistent Volume Management
249
250
Manage storage resources including persistent volumes and persistent volume claims.
251
252
```python { .api }
253
class CoreV1Api:
254
def create_persistent_volume(
255
self,
256
body: V1PersistentVolume,
257
dry_run: str = None,
258
field_manager: str = None,
259
pretty: str = None
260
) -> V1PersistentVolume:
261
"""Create a persistent volume."""
262
263
def create_namespaced_persistent_volume_claim(
264
self,
265
namespace: str,
266
body: V1PersistentVolumeClaim,
267
dry_run: str = None,
268
field_manager: str = None,
269
pretty: str = None
270
) -> V1PersistentVolumeClaim:
271
"""Create a persistent volume claim in specified namespace."""
272
273
def list_persistent_volume(
274
self,
275
pretty: str = None,
276
allow_watch_bookmarks: bool = None,
277
continue_: str = None,
278
field_selector: str = None,
279
label_selector: str = None,
280
limit: int = None,
281
resource_version: str = None,
282
timeout_seconds: int = None,
283
watch: bool = None
284
) -> V1PersistentVolumeList:
285
"""List persistent volumes."""
286
```
287
288
### Node Management
289
290
Read and monitor cluster nodes and their status.
291
292
```python { .api }
293
class CoreV1Api:
294
def list_node(
295
self,
296
pretty: str = None,
297
allow_watch_bookmarks: bool = None,
298
continue_: str = None,
299
field_selector: str = None,
300
label_selector: str = None,
301
limit: int = None,
302
resource_version: str = None,
303
timeout_seconds: int = None,
304
watch: bool = None
305
) -> V1NodeList:
306
"""List cluster nodes."""
307
308
def read_node(
309
self,
310
name: str,
311
pretty: str = None
312
) -> V1Node:
313
"""Read specified node."""
314
```
315
316
## Resource Models
317
318
### V1Pod
319
```python { .api }
320
class V1Pod:
321
api_version: str # "v1"
322
kind: str # "Pod"
323
metadata: V1ObjectMeta
324
spec: V1PodSpec
325
status: V1PodStatus
326
```
327
328
### V1Service
329
```python { .api }
330
class V1Service:
331
api_version: str # "v1"
332
kind: str # "Service"
333
metadata: V1ObjectMeta
334
spec: V1ServiceSpec
335
status: V1ServiceStatus
336
```
337
338
### V1Namespace
339
```python { .api }
340
class V1Namespace:
341
api_version: str # "v1"
342
kind: str # "Namespace"
343
metadata: V1ObjectMeta
344
spec: V1NamespaceSpec
345
status: V1NamespaceStatus
346
```
347
348
### V1ConfigMap
349
```python { .api }
350
class V1ConfigMap:
351
api_version: str # "v1"
352
kind: str # "ConfigMap"
353
metadata: V1ObjectMeta
354
binary_data: dict # Binary data
355
data: dict # String data
356
immutable: bool
357
```
358
359
### V1Secret
360
```python { .api }
361
class V1Secret:
362
api_version: str # "v1"
363
kind: str # "Secret"
364
metadata: V1ObjectMeta
365
data: dict # Base64 encoded data
366
string_data: dict # Plain text data
367
type: str # Secret type (Opaque, kubernetes.io/service-account-token, etc.)
368
immutable: bool
369
```
370
371
### V1PersistentVolume
372
```python { .api }
373
class V1PersistentVolume:
374
api_version: str # "v1"
375
kind: str # "PersistentVolume"
376
metadata: V1ObjectMeta
377
spec: V1PersistentVolumeSpec
378
status: V1PersistentVolumeStatus
379
```
380
381
### V1Eviction
382
```python { .api }
383
class V1Eviction:
384
api_version: str # "policy/v1"
385
kind: str # "Eviction"
386
metadata: V1ObjectMeta
387
delete_options: V1DeleteOptions
388
389
### V1Binding
390
```python { .api }
391
class V1Binding:
392
api_version: str # "v1"
393
kind: str # "Binding"
394
metadata: V1ObjectMeta
395
target: V1ObjectReference
396
397
### V1DeleteOptions
398
```python { .api }
399
class V1DeleteOptions:
400
api_version: str
401
kind: str
402
dry_run: list[str]
403
grace_period_seconds: int
404
orphan_dependents: bool
405
preconditions: V1Preconditions
406
propagation_policy: str
407
```
408
409
### V1PersistentVolumeClaim
410
```python { .api }
411
class V1PersistentVolumeClaim:
412
api_version: str # "v1"
413
kind: str # "PersistentVolumeClaim"
414
metadata: V1ObjectMeta
415
spec: V1PersistentVolumeClaimSpec
416
status: V1PersistentVolumeClaimStatus
417
```
418
419
## Usage Examples
420
421
### Creating a Pod
422
423
```python
424
from kubernetes import client, config
425
426
config.load_kube_config()
427
v1 = client.CoreV1Api()
428
429
pod_manifest = {
430
"apiVersion": "v1",
431
"kind": "Pod",
432
"metadata": {
433
"name": "nginx-pod",
434
"labels": {"app": "nginx"}
435
},
436
"spec": {
437
"containers": [{
438
"name": "nginx",
439
"image": "nginx:1.20",
440
"ports": [{"containerPort": 80}],
441
"env": [{"name": "ENV_VAR", "value": "test"}]
442
}]
443
}
444
}
445
446
# Create the pod
447
pod = v1.create_namespaced_pod(namespace="default", body=pod_manifest)
448
print(f"Pod created: {pod.metadata.name}")
449
```
450
451
### Managing Services
452
453
```python
454
from kubernetes import client, config
455
456
config.load_kube_config()
457
v1 = client.CoreV1Api()
458
459
service_manifest = {
460
"apiVersion": "v1",
461
"kind": "Service",
462
"metadata": {"name": "nginx-service"},
463
"spec": {
464
"selector": {"app": "nginx"},
465
"ports": [{
466
"port": 80,
467
"targetPort": 80,
468
"protocol": "TCP"
469
}],
470
"type": "ClusterIP"
471
}
472
}
473
474
# Create service
475
service = v1.create_namespaced_service(namespace="default", body=service_manifest)
476
print(f"Service created: {service.metadata.name}")
477
478
# List services
479
services = v1.list_namespaced_service(namespace="default")
480
for svc in services.items:
481
print(f"Service: {svc.metadata.name}, ClusterIP: {svc.spec.cluster_ip}")
482
```
483
484
### Working with ConfigMaps
485
486
```python
487
from kubernetes import client, config
488
489
config.load_kube_config()
490
v1 = client.CoreV1Api()
491
492
configmap_manifest = {
493
"apiVersion": "v1",
494
"kind": "ConfigMap",
495
"metadata": {"name": "app-config"},
496
"data": {
497
"database_url": "postgresql://localhost:5432/mydb",
498
"debug": "true",
499
"max_connections": "100"
500
}
501
}
502
503
# Create ConfigMap
504
cm = v1.create_namespaced_config_map(namespace="default", body=configmap_manifest)
505
print(f"ConfigMap created: {cm.metadata.name}")
506
```