What is Deployment ?
Deployment provides
replication functionality with the help of ReplicaSets, along with various
additional capability like rolling out of changes, rollback changes if
required.
Deployment flow :-
3.1
Benefits of Deployment - Rollout Changes
We can
easily roll out new updates to our application using deployments.
Deployments
will perform an update in a rollout manner to ensure that your app is not down.
1. Rollout
nginx to nginx:1.17.3
1. Create
a first deployment.
# cat deployment/first.yaml
apiVersion:
apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: nginx-container
image: nginx:1.17.3
# kubectl
apply -f first.yaml
# kubectl
describe deployments test-deployment
# kubectl get deploy
# kubectl get rs
# kubectl
rollout status deploy test-deployment
# kubectl
rollout history deploy test-deployment
# kubectl
rollout history deploy test-deployment --revision 2
2.Deployment
Strategies types :-
1.Recreate
:-
In this type
of very simple deployment, all of the old pods are killed all at once and get
replaced all at once with the new ones.
2.RollingUpdate ( Ramped or Incremental )
:-
The rolling deployment is the standard default
deployment to Kubernetes. It works by slowly, one by one, replacing pods of the
previous version of your application with pods of the new version without any
cluster downtime.
3.Canary :-
10 instances, first 2 instance deployed new version
& test is done then new version deployed on 8 instances. Full deployment
has been done, after that old version instance will be deleted.
4.blue / Green :-
In a blue/green deployment strategy (sometimes referred to as red/black) the old version of the application (green) and the new version (blue) get deployed at the same time. When both of these are deployed, users only have access to the green; whereas, the blue is available to your QA team for test automation on a separate service or via direct port-forwarding.
3 Benefits of Deployment - Rollback Changes
Sometimes,
you may want to rollback a Deployment; for example, when the Deployment is not
stable, such as crash looping
Deployment
ensures that only a certain number of Pods are down while they are being
updated.
By default,
it ensures that at least 25% of the desired number of Pods are up (25% max
unavailable)
Deployments
keep the history of revisions that had been made.
Rolling
back to revision=1
# kubectl
rollout undo deploy test-deployment --to-revision=1
# kubectl
describe deployments test-deployment
Revision=1
will be removed from the rollout history deployment.
# kubectl rollout history deploy test-deployment
Create an
object via CLI :-
1. Create
a Deployment:
# kubectl
create deployment <deployment-name>
--image=<image-name>:<tag>
Generating
deployment Manifest via CLI Dry run :-
# kubectl
create deployment my-deployment --image=nginx --replicas 3 --dry-run=client -o yaml
# kubectl
create deployment --help
2.Get
Deployments:
# kubectl get deployments
3.Describe
a Deployment:
# kubectl describe deployment <deployment-name>
4.Update
a Deployment's Image:
# kubectl set image deployment/<deployment-name> <container-name>=<new-image-name>:<tag>
5.Scale a
Deployment:
# kubectl scale deployment <deployment-name> --replicas=<number-of-replicas>
6.Rollout
Status of a Deployment:
# kubectl rollout status deployment/<deployment-name>
7.Rolling
Back a Deployment:
# kubectl rollout undo deployment/<deployment-name>
8.Pause
and Resume a Deployment:
# kubectl
rollout pause deployment/<deployment-name>
# kubectl rollout resume deployment/<deployment-name>
9.Edit a
Deployment:
# kubectl edit deployment <deployment-name>
10.Delete
a Deployment:
# kubectl
delete deployment <deployment-name>
No comments:
Post a Comment