Skip to main content

kubernetes deployment summary and commands

Rolling updates:
suppose one the updates resulted in some error and we would like to roll back the changes.
or may want to pause the environment, make the changes and resume so that the changes are rolled out together

How do we create a deployment file
everything will be same as replicaset in the yml file except that the kind now will be Deployment

commands
kubectl create -f deployment-ymlFile

kubectl get deployments

kubectl get replicaset (deployment automatically creates replicaset)

kubectl get pods

to see all the created objects at once
kubectl get all
apiVersion: apps/v1

kind: Deployment

metadata:
  name: myapp-deployment
  labels:
    name: myapp
    type: front-end

spec:
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        type: front-end
    spec:
      containers:
        - name: nginx-controller
          image: nginx
  replicas: 3
  selector:
    matchLabels:
      type: front-end

in most of the cases we will not be creating pod  definition or replica set file and would be directly creating the deployment file


Rollout and versioning in deployment

when we create a deployment it triggers a rollout, a new rollout creates a new deployment revision.
When container version is updated, a new rollour is triggerd and a new deployment revision is created named revision2.
This helps us keep track of changes made to our deployment and enables us to roll back to previous version of the deployment  if required.

we can see the rollout status by
kubectl rolllout status deployment/<name of the deployment>

to see the history and revision of rollout
kubectl rollout history deplyment/<name of deployment>

Deployment strategy

1. Recreate strategy
 delete all  the existing once and deploy the new one
problem: system will inaccessible to users the while the system is down
(this is not the default )

2.  Rolling Update
in this, we take down the existing once one by one. This way the system never goes down and the upgrade is seamless.


How to apply the changes

Kubectl apply
kubectl apply -f deployment-definition

by setting image
kubectl set image deployment/myapp-dep \nginx= nginx:1.9.1
the only problem is that doing it this way will result in the deployment file having a different definition

to see the history of deployment we can use, in this we can find the strategy used
kubectl describe deployment

undo update 
kubectl rollout undo deployment/myapp-deployment

 perform deplyment only with image name and no definition file

kubectl run nginx --image=nginx

summary of deployment commands

create
kubectl create -f deployment deployment-definition.yml

get
kubectl get deployments

update
kubectl apply -f deployment-definition.yml
kubectl set image deployment/myapp-deployment nginx=nginx:1.9.1

status
kubectl rollout status deployment/myapp-deployment

kubectl rollout history deployment/myapp-deployment

rollback
 kubectl rollout undo deployment/myapp-deployment

in the history command if you want to see the CHANGE-CAUSE , for this we will have to issue a record command when we create cluster
eg.
kubectl create -f deployment-definition.yml --record



Comments

Popular posts from this blog

Gui logging in node js and python

For node.js Use  frontail for logging https://www.npmjs.com/package/frontail For Python -- use Cutelog https://pypi.org/project/cutelog/ In NodeJs for using frontail we need to use log the logs in a file for logging logs to file , we will use winston Using winston https://www.npmjs.com/package/winston Eg. of using winstonconst { createLogger, format, transports } = require('winston'); const { combine, timestamp, label, prettyPrint } = format; const logger = createLogger({   level: 'info',   format: format.json(),   transports: [     //     // - Write to all logs with level `info` and below to `combined.log`      // - Write all logs error (and below) to `error.log`.     //     new transports.File({ filename: 'error.log', level: 'error' }),     new transports.File({ filename: 'combined.log' })   ] }); logger.log({   level: 'info',   message: 'What time is...

opening multiple ports tunnels ngrok in ubuntu

Location for the config yml file /home/example/.ngrok2/ngrok.yml content of config file authtoken: 4nq9771bPxe8ctg7LKr_2ClH7Y15Zqe4bWLWF9p tunnels: app-foo: addr: 80 proto: http host_header: app-foo.dev app-bar: addr: 80 proto: http host_header: app-bar.dev how to start ngrok with considering the config file: ngrok start --all

rename field in elastic Search

https://qiita.com/tkprof/items/e50368eb1473497a16d0 How to Rename an Elasticsearch field from columns: - {name: xxx, type: double} to columns: - {name: yyy, type: double} Pipeline API and reindex create a new Pipeline API : Rename Processor PUT _ingest/pipeline/pipeline_rename_xxx { "description" : "rename xxx", "processors" : [ { "rename": { "field": "xxx", "target_field": "yyy" } } ] } { "acknowledged": true } then reindex POST _reindex { "source": { "index": "source" }, "dest": { "index": "dest", "pipeline": "pipeline_rename_xxx" } }