You can use the Kubernetes
python package to connect to your local cluster, to perform tasks such as fetching a configmap
.
Use load_incluster_config()
to load the config inside the cluster.
Here’s a simple example:
from kubernetes import client, config
config.load_incluster_config()
v1 = client.CoreV1Api()
config_map = v1.read_namespaced_config_map("my-configmap", namespace="kubeflow-mynamespace")
print(config_map)
Sample output:
{'api_version': 'v1',
'binary_data': None,
'data': {'MY_VAR': 'MY_VALUE'},
'immutable': None,
'kind': 'ConfigMap',
'metadata': {'annotations': {'kubectl.kubernetes.io/last-applied-configuration': '{"apiVersion":"v1","data":{"MY_VAR":"MY_VALUE"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"my-configmap","namespace":"kubeflow-brad"}}\\n'},
'cluster_name': None,
'creation_timestamp': datetime.datetime(2023, 8, 4, 16, 15, 11, tzinfo=tzlocal()),
'deletion_grace_period_seconds': None,
'deletion_timestamp': None,
'finalizers': None,
'generate_name': None,
'generation': None,
'labels': None,
'managed_fields': [{'api_version': 'v1',
'fields_type': 'FieldsV1',
'fields_v1': {'f:data': {'.': {},
'f:my-key': {}}},
'manager': 'kubectl-create',
'operation': 'Update',
'time': datetime.datetime(2023, 8, 4, 16, 15, 11, tzinfo=tzlocal())},
{'api_version': 'v1',
'fields_type': 'FieldsV1',
'fields_v1': {'f:data': {'f:MY_VAR': {}},
'f:metadata': {'f:annotations': {'.': {},
'f:kubectl.kubernetes.io/last-applied-configuration': {}}}},
'manager': 'kubectl-client-side-apply',
'operation': 'Update',
'time': datetime.datetime(2024, 5, 3, 14, 12, 40, tzinfo=tzlocal())}],
'name': 'my-configmap',
'namespace': 'kubeflow-mynamespace',
'owner_references': None,
'resource_version': '688365448',
'self_link': None,
'uid': '7d964edf-98d9-4750-be20-475841d459e1'}}