Why do you need deployment?
Course: Kubernetes Part 1 - chapter 16
If all that a deployment does is create a replicaset , why cant we just create rs ?
Experiment
Section titled “Experiment”Update the image to be nginx2 (an image that doesnt exist)
apiVersion: apps/v1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx2:latest ports: - containerPort: 80- Apply the new deployment
kubectl apply -f deployment.yml- Check the new
rsnow
kubectl get rsNAME DESIRED CURRENT READY AGEnginx-deployment-576c6b7b6 3 3 3 14mnginx-deployment-5fbd4799cb 1 1 0 10m- Check the pods
kubectl get podsNAME READY STATUS RESTARTS AGEnginx-deployment-576c6b7b6-9nlnq 1/1 Running 0 15mnginx-deployment-576c6b7b6-m8ttl 1/1 Running 0 16mnginx-deployment-576c6b7b6-n9cx4 1/1 Running 0 16mnginx-deployment-5fbd4799cb-fmt4f 0/1 ImagePullBackOff 0 12mRole of deployment
Section titled “Role of deployment”Deployment ensures that there is a smooth deployment, and if the new image fails for some reason, the old replicaset is maintained.
Even though the rs is what does pod management , deployment is what does rs management
Rollbacks
Section titled “Rollbacks”- Check the history of deployment
kubectl rollout history deployment/nginx-deployment- Undo the last deployment
kubectl rollout undo deployment/nginx-deploymentCreate a new deployment
Section titled “Create a new deployment”- Replace the image to be
postgres
apiVersion: apps/v1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: postgres:latest ports: - containerPort: 80-
Check the new set or
rs
-
Check the pods

-
Check pods after some time

-
Check the logs
kubectl logs -f nginx-deployment-7cdb767447-4d5drError: Database is uninitialized and superuser password is not specified. You must specify POSTGRES_PASSWORD to a non-empty value for the superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all connections without a password. This is *not* recommended.
See PostgreSQL documentation about "trust": https://www.postgresql.org/docs/current/auth-trust.html- Update the manifest to pass
POSTGRES_PASSWORD
apiVersion: apps/v1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: postgres:latest ports: - containerPort: 80 env: - name: POSTGRES_PASSWORD value: "yourpassword"- Check pods now
kubectl get pods
- Try after some time

Postgres is running correctly
- Check the rs
