<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 How to create a ConfigMap and use its data in Pods
ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable. In this notebook we would learn how to create a ConfigMap and also how to use its data in Pods as seen in https
Step1:  Load config from default location
Step2:  Create API endpoint instance and API resource instances
Step3:  Create key value pair data for the ConfigMap
Step4:  Create ConfigMap
Step5:  Create API endpoint instance and API resource instances for test Pod
Step6:  Initialize test Pod container
Step7:  Define Pod environment variables with data from ConfigMaps
Step8:  Create Pod
Step9:  View ConfigMap data from Pod log
Step10:  Delete ConfigMap
Step11:  Delete Pod
<ASSISTANT_TASK:>
Python Code:
from kubernetes import client, config
from kubernetes.client.rest import ApiException
Explanation: How to create a ConfigMap and use its data in Pods
ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable. In this notebook we would learn how to create a ConfigMap and also how to use its data in Pods as seen in https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/
End of explanation
config.load_kube_config()
Explanation: Load config from default location
End of explanation
api_instance = client.CoreV1Api()
cmap = client.V1ConfigMap()
Explanation: Create API endpoint instance and API resource instances
End of explanation
cmap.metadata = client.V1ObjectMeta(name="special-config")
cmap.data = {}
cmap.data["special.how"] = "very"
cmap.data["special.type"] = "charm"
Explanation: Create key value pair data for the ConfigMap
End of explanation
api_instance.create_namespaced_config_map(namespace="default", body=cmap)
Explanation: Create ConfigMap
End of explanation
pod = client.V1Pod()
spec = client.V1PodSpec()
pod.metadata = client.V1ObjectMeta(name="dapi-test-pod")
Explanation: Create API endpoint instance and API resource instances for test Pod
End of explanation
container = client.V1Container()
container.name = "test-container"
container.image = "gcr.io/google_containers/busybox"
container.command = ["/bin/sh", "-c", "env"]
Explanation: Initialize test Pod container
End of explanation
container.env = [client.V1EnvVar(name="SPECIAL_LEVEL_KEY"), client.V1EnvVar(name="SPECIAL_TYPE_KEY")]
container.env[0].value_from = client.V1EnvVarSource()
container.env[0].value_from.config_map_key_ref = client.V1ConfigMapKeySelector(name="special-config", key="special.how")
container.env[1].value_from = client.V1EnvVarSource()
container.env[1].value_from.config_map_key_ref = client.V1ConfigMapKeySelector(name="special-config", key="special.type")
spec.restart_policy = "Never"
spec.containers = [container]
pod.spec = spec
Explanation: Define Pod environment variables with data from ConfigMaps
End of explanation
api_instance.create_namespaced_pod(namespace="default",body=pod)
Explanation: Create Pod
End of explanation
log = ""
try: 
    log = api_instance.read_namespaced_pod_log(name="dapi-test-pod", namespace="default")
except ApiException as e:
    if str(e).find("ContainerCreating") != -1:
        print("Creating Pod container.\nRe-run current cell.")
    else:
        print("Exception when calling CoreV1Api->read_namespaced_pod_log: %s\n" % e)
for line in log.split("\n"):
    if line.startswith("SPECIAL"):
        print(line)
Explanation: View ConfigMap data from Pod log
End of explanation
api_instance.delete_namespaced_config_map(name="special-config", namespace="default", body=cmap)
Explanation: Delete ConfigMap
End of explanation
api_instance.delete_namespaced_pod(name="dapi-test-pod", namespace="default", body=client.V1DeleteOptions())
Explanation: Delete Pod
End of explanation
<END_TASK>