In this project, I would like to show core feature of Kubernetes. Kubernetes is orchestrion tool for applications. Applications code is stored in Docker images. If something is smaller, it may have less vulnerabilities. Even single vulnerability is threat for application. Pods are the smallest deployable unit in Kubernetes. More information in offication dokumentation (1).
To keep whole infrastructure under control, all definition must stays as code stored in Repository. Below is presented Pod manifest. In Screnshoot below, in line "3" is declared type of manifest.
In this Pod manifest we can see declaration of "nginx" Docker image. Docker images is pulled from DockerHub. If sufix of docker image is blank, Kubernets assume it need pull latest version.
To incorporate manifest, run command:
kubectl create -f ./pod.yaml
Comannd need to be executed in directory where file is stored. In command is used related file path.
Apps are built for customers. It mean that are more than 1. In that case Pods also need be many to each customer. Key argument for cloud is scalility. Reasources shoudl be scalable, to if create them if need occur.
Here is example of reusage of Pod declaration, and expanded as ReplicaSet object. In file in paragraf Spec>replicas (see fileline 8-9) is defined how many copies SPEC>TEMPLATE(fileline 14 - end) of Pod will be created.
Important remark !!!
Docker image must have define specific version. It is critical in case Disaster Recovery or any situation when Pods need be recreated.
I creared deployment by kubectl apply -f ./deployment.yaml --record
Deployment type allow as to manage release, if update Docker image will be necessary.
Flag " --record " grap info of each release and store in roll out history.
kubectl rollout status deployment.apps/myapp-deployment-rollback
To update container version I use command
kubectl edit deployment/<metadata-app-name>
Deployment manifest open in default code editor in my case it was VIM.
After incorporation changes save by command :wq
To see changes run command:
kubectl rollout status deployment.apps/myapp-deployment-rollback
To see rollout history run command:
kubectl rollout history deployment.apps/myapp-deployment-rollback
I made few rollout with with rump up contrainer revision
REV 1 > REV 2 > REV 3 > REV 4
ngnix:1.15 > ngnix:1.16 > ngnix:1.17 > ngnix:1.18
Rollout shoud have been smooth, that customer not notice roll out. Default roll out, create new Pod with updated container version. Then and ONLY then new POD is working correctly, old POD is terminated. Kubernetes such mechnizm, that during roll out faillure occur, roll out stop, old pods are continue normall as ususal. When roll out is successful new revision save in history.
I made rollout undo from REV. 4 to REV. 2. by commnd bellow.
kubectl rollout undo deployment.apps/myapp-deployment-rollback --to-revision=2
At end of day I stop minikube, to continue in future.
CheatSheet:
Create:
kubectl create -f ./<file-name>
Get:
kubectl get deployments
Update:
kubectl apply -f ./<file-name>
kubectl set image deployment/<metadata-app-name> <new Docker image version>
Status:
kubectl rollout status deployment/<metadata-app-name>
kubectl rollout history deployment/<metadata-app-name>
Rollback (3):
kubectl rollout undo deployment/<metadata-app-name>
DOKU:
1. https://kubernetes.io/docs/concepts/workloads/pods/
2. https://hub.docker.com/_/nginx
3. https://kubernetes.io/docs/reference/kubectl/generated/kubectl_rollout/kubectl_rollout_undo/









No comments:
Post a Comment