<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 Deployment
In this notebook, we show you how to create a Deployment with 3 ReplicaSets. These ReplicaSets are owned by the Deployment and are managed by the Deployment controller. We would also learn how to carry out RollingUpdate and RollBack to new and older versions of the deployment.
Step1:  Load config from default location
Step2:  Create Deployment object
Step3:  Fill required Deployment fields (apiVersion, kind, and metadata)
Step4:  A Deployment also needs a .spec section
Step5:  Add Pod template in .spec.template section
Step6:  Pod template container description
Step7:  Create Deployment
Step8:  Update container image
Step9:  Apply update (RollingUpdate)
Step10:  Delete Deployment
<ASSISTANT_TASK:>
Python Code:
from kubernetes import client, config
Explanation: How to create a Deployment
In this notebook, we show you how to create a Deployment with 3 ReplicaSets. These ReplicaSets are owned by the Deployment and are managed by the Deployment controller. We would also learn how to carry out RollingUpdate and RollBack to new and older versions of the deployment.
End of explanation
config.load_kube_config()
apps_api = client.AppsV1Api()
Explanation: Load config from default location
End of explanation
deployment = client.V1Deployment()
Explanation: Create Deployment object
End of explanation
deployment.api_version = "apps/v1"
deployment.kind = "Deployment"
deployment.metadata = client.V1ObjectMeta(name="nginx-deployment")
Explanation: Fill required Deployment fields (apiVersion, kind, and metadata)
End of explanation
spec = client.V1DeploymentSpec()
spec.replicas = 3
Explanation: A Deployment also needs a .spec section
End of explanation
spec.template = client.V1PodTemplateSpec()
spec.template.metadata = client.V1ObjectMeta(labels={"app": "nginx"})
spec.template.spec = client.V1PodSpec()
Explanation: Add Pod template in .spec.template section
End of explanation
container = client.V1Container()
container.name="nginx"
container.image="nginx:1.7.9"
container. ports = [client.V1ContainerPort(container_port=80)]
spec.template.spec.containers = [container]
deployment.spec = spec
Explanation: Pod template container description
End of explanation
apps_api.create_namespaced_deployment(namespace="default", body=deployment)
Explanation: Create Deployment
End of explanation
deployment.spec.template.spec.containers[0].image = "nginx:1.9.1"
Explanation: Update container image
End of explanation
apps_api.replace_namespaced_deployment(name="nginx-deployment", namespace="default", body=deployment)
Explanation: Apply update (RollingUpdate)
End of explanation
apps_api.delete_namespaced_deployment(name="nginx-deployment", namespace="default", body=client.V1DeleteOptions(propagation_policy="Foreground", grace_period_seconds=5))
Explanation: Delete Deployment
End of explanation
<END_TASK>