Hello DevSecOps, SRE or Platform Engineer or DevOps Engineers, In this post I want to discuss, Understanding of Kubernetes deployment it's hierarchy of kube objects. Declaratives and imperative ways to make deployment on kube clusters.
How to deploy an application on
Kubernetes pods, just follow these steps as shown in this post.
Here is new learning, I would like to share with you about Kubernetes deployment hierarchy, which internally calls the replication controller to make desired number of replicas of pod temple specified.
Kubernetes Deployment hierarchy |
Let's go to have a deep understanding about Kubernetes deployment hierarchy.
1. Generating Kubernetes Deployment Manifest file
We need to create a YAML file to define the deployment of the 'httpd' Apache Webserver. Here we are going to use the '--dry-run' option with client as value and '-o yaml' to generate the YAML file, to redirect the output we can use the greater than symbol to store in a file. e.g: httpd-deploy.yaml
Command :
k create deploy httpd-deploy --image=httpd:alpine --dry-run=client -o yaml k create deploy httpd-deploy --image=httpd:alpine --dry-run=client -o yaml >httpd-deploy.yaml vi httpd-deploy.yamlWe can modify the httpd-deploy.yaml file as per our requirements such as changing the Image tag value so that we can reuse it for every new version available on the Docker Hub that is public repository.
apiVersion: apps/v1 kind: Deployment metadata: labels: app: httpd-deploy name: httpd-deploy spec: replicas: 1 selector: matchLabels: app: httpd-deploy strategy: {} template: metadata: labels: app: httpd-deploy spec: containers: - image: httpd:alpine name: httpdTo create,confirm the deployment we can use the following commands
k create -f httpd-deploy.yaml #create k get deploy,po #confirmation
Listing deployments
The 'kubectl' command will allow us to use the object either 'deployments' or 'deploy' or even singular word 'deployment' to list all the Deployments of default namespacekubectl get deployments # or use alias name kubectl get deploy # or use alternative name kubectl get deployment
Validate deployment history
We can describe the Deployment object details as follows:kubectl describe deploy web-deploymentDeployments contains Pods and its Replica information.
To Show Rollout History of the given Deployment
kubectl rollout history deployment web-deployment
4. Create/Update deployments using Image tags
Updates the existing deployment using update application new version. Do some R&D work here. Goto the Docker Hub find the Niginx tags consider the version tags to deploy. Currently I could see 1.22.0 and 1.23.1 versioned tags. So start with the new deployment with nginx:1.22.0 image after the pods up and application looks good we can update to the latest version that is nginx:1.23.1 versioned image.k create deploy web-deploy --image=nginx:1.22 --replicas=2 k get deploy,po -o wide # upgrade to new version 1.24 k set image deploy/web-deploy nginx=nginx:1.24 k get deploy,po -o wide
5. Rollback/Rollforward Revisions
Rolls back or roll Forward to a specific revision versions can be done as follows:Use the same strategy to create the app-deploy.yml file as given in the above; Do type the following commands to avoid the hyphenation issues.
Example app-deploy.yml as below:
The following image will shows the Rollback example clearly
Example app-deploy.yml as below:
apiVersion: apps/v1 kind: Deployment metadata: labels: app: app-deploy name: app-deploy spec: replicas: 1 selector: matchLabels: app: app-deploy template: metadata: labels: app: app-deploy spec: containers: - image: httpd:2.4.59-alpine name: httpdNow let's play for the the rollback option, where we will have some number of revisions recorded and we can navigate to the previous version using 'rollout undo' with '--to-revision' option.
kubectl create –f app-deploy.yml kubectl get deploy app-deploy kubectl apply –f app-deploy.yml --record k rollout history deployment app-deploy k set image deploy/app-deploy httpd=httpd:2.4.59-bookworm --record k rollout history deployment app-deploy k set image deploy/app-deploy httpd=httpd:2.4-bookworm --record k set image deploy/app-deploy httpd=httpd:bookworm --record k rollout history deployment app-deploy k rollout undo deploy/app-deploy --to-revision=3 k get deploy,po -o wide
The following image will shows the Rollback example clearly
Hope you got the bit taste of Kubernetes Deployment. Write back your comment with suggestion or what you learnt from this post.
No comments:
Post a Comment