<jupyter_start><jupyter_text>How to start a Pod==================In this notebook, we show you how to create a single container Pod.Start by importing the Kubernetes module-----------------------------------------<jupyter_code>from kubernetes import client, config<jupyter_output><empty_output><jupyter_text>If you are using a proxy, you can use the _client Configuration_ to setup the host that the client should use. Otherwise read the kubeconfig file.<jupyter_code>config.load_incluster_config()<jupyter_output><empty_output><jupyter_text>Pods are a stable resource in the V1 API group. Instantiate a client for that API group endpoint.<jupyter_code>v1=client.CoreV1Api()
pod=client.V1Pod()
spec=client.V1PodSpec()
pod.metadata=client.V1ObjectMeta(name="busybox")<jupyter_output><empty_output><jupyter_text>In this example, we only start one container in the Pod. The container is an instnace of the _V1Container_ class.<jupyter_code>container=client.V1Container()
container.image="busybox"
container.args=["sleep", "3600"]
container.name="busybox"<jupyter_output><empty_output><jupyter_text>The specification of the Pod is made of a single container in its list.<jupyter_code>spec.containers = [container]
pod.spec = spec<jupyter_output><empty_output><jupyter_text>Get existing list of Pods, before the creation of the new Pod.<jupyter_code>ret = v1.list_namespaced_pod(namespace="default")
for i in ret.items:
    print("%s  %s  %s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))<jupyter_output><empty_output><jupyter_text>You are now ready to create the Pod.<jupyter_code>v1.create_namespaced_pod(namespace="default",body=pod)<jupyter_output><empty_output><jupyter_text>Get list of Pods, after the creation of the new Pod. Note the newly created pod with name "busybox"<jupyter_code>ret = v1.list_namespaced_pod(namespace="default")
for i in ret.items:
    print("%s  %s  %s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))<jupyter_output><empty_output><jupyter_text>Delete the Pod--------------You refer to the Pod by name, you need to add its namespace and pass some _delete_ options.<jupyter_code>v1.delete_namespaced_pod(name="busybox", namespace="default", body=client.V1DeleteOptions())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13093652907234798, 'fraction_numerical': 0.007545494895694629, 'mean_word_length': 6.390163934426229, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '351080', 'license': 'Apache-2.0', 'n_tokens_mistral': 738, 'n_tokens_neox': 725, 'n_words': 189, 'path': 'examples/notebooks/create_pod.ipynb', 'repo_name': 'sivansyuee/python', 'size': '2253'}