# Kubernetes Deployment Object

A Kubernetes Deployment is a declarative object that manages Pods and ReplicaSets. It provides declarative updates for Pods and ReplicaSets.

Some key points about Deployments:

* A Deployment provides a declarative pattern for how you want your Pods to be created and updated.
    
* A Deployment controls the ReplicaSets for the Pods it manages. When you update a Deployment, it will create a new ReplicaSet and gradually roll out the new version of the application.
    
* Deployments maintain a history of updates so that you can rollback to previous revisions if needed.
    
* You specify a Pod template in the Deployment that contains the desired state for the Pods.
    
* The Deployment controller changes the actual state to match the desired state specified in the Pod template.
    

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3  
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec: 
      containers:
      - name: nginx
        image: nginx:1.14.2
```

Here we have defined:

* `apiVersion`: The version of the API used to create this Deployment object
    
* `kind`: Tells Kubernetes this is a Deployment
    
* [`metadata.name`](http://metadata.name): The name of the Deployment
    
* `spec.replicas`: The number of Pods we want to run (3 in this case)
    
* `spec.selector`: The label selector used to identify the Pods this Deployment manages
    
* `spec.template`: The Pod template that defines the desired state of the Pods. This contains:
    
    * `template.metadata.labels`: The labels to apply to each Pod
        
    * `template.spec`: The PodSpec defining the container image to use (`nginx:1.14.2`)
        

When you apply this Deployment, the Deployment controller will create 3 Pods matching the Pod template. If any of those Pods fail or are deleted, the Deployment controller will recreate them to match the desired state.

You can update a Deployment by updating its Pod template. The Deployment controller will roll out the new version in a controlled fashion.

Hope this helps explain the basics of Kubernetes Deployments! Let me know if you have any other questions.
