Knowledge Bank
  • My GitBook
  • Miscellaneous
  • Project
    • Rider and Intellij
    • Code
    • Frontend
      • Condition
      • AddConditionModalDialog
    • Backend
    • e2e
      • fragments
  • JAVASCRIPT
    • Promise
    • Destructuring
    • Spread Syntax and Rest Parameters
    • Typescript
      • Examples of Types
      • React Typescript
    • This
    • Dot Notation vs Bracket Notation
    • Shallow vs Deep Clone
    • New ES Edition
  • C#
    • Project Note
    • Basic
    • Shortcut and Debugging
  • Programming Paradigms
    • SOLID Principles
    • Object Oriented Programming (OOP)
      • Evolution of OOP (Procedural to OOP)
      • Instantiation
      • 4 Pillars of OOP
      • Extra
    • Functional Programming (FP)
      • Idempotent
      • Imperative vs Declarative
      • Immutability
      • High Order Function and Closure
      • Currying
      • Partial Application
      • Memoization and Caching
      • Compose and Pipe
      • Extra
      • Example of FP
    • OOP vs FP
      • Composition vs Inheritance
  • DATA STRUCTURE
    • Big O
    • Data Structure
    • Array
    • Hash Table
    • Linked List
    • Queue and Stack
    • Tree
      • Binary Heap
      • Trie
    • Graph
      • Example of Graph
  • React-Redux
    • MobX
    • Best Practices
  • Algorithms
    • Recursion
      • Examples of Recursion
    • Sorting
    • Searching and Traversal
    • Dynamic Programming
  • REFACTORING
    • Clean Code
      • Formatting
      • Error Handling
      • Concurrency
      • Testing
      • SOLID Principles
      • Classes
      • Objects and Data Structures
      • Variables
      • Functions
    • Code Smells
      • Long Function
      • Duplicate Code
      • Loops
      • Double Negative
      • Christmas Tree Code
      • Complex Condition
      • Primitive Obsession
      • Speculative Generality
      • God Class
      • Long Parameter List
  • Junior to Senior
    • AWS
      • Lambda
    • Session + Authentication
    • Redis
    • Kubernetes
      • Networking
      • Services
      • Deployment
      • Replica Set
      • YAML
      • pod-definition.yml
      • Kubectl
      • Pods
      • Fundamentals
    • Docker
      • Operating System - Extra
      • Dockerfile - Docker Image
      • Docker Storage
      • Docker Network
      • Docker Registry
      • Docker Command
      • Docker Compose
      • Docker Compose - Postgres
    • Security
      • Logging
      • HTTPS, Cross-Site-Scripting (XSS) and Cross-Site-Request-Forgery (CSRF)
      • 3rd Party Library
      • Injection
      • Code Secret, Secure Header, Access Control, Data Management, Authentication
    • CI/CD
    • SPA vs Server-Side Rendering
    • Performance
      • Optimized Code
      • Critical Render Path
      • Backend Optimization
      • Minimized Files and Images
      • Minimized Delivery
  • SECURITY
    • Encryption
    • SSH
  • Command
  • Cheatsheet
    • NPM
    • GIT
  • Writing Template
    • Guide
    • API
    • ChangeLog
    • FAQ
  • Linux
Powered by GitBook
On this page

Was this helpful?

  1. Junior to Senior
  2. Kubernetes

Deployment

PreviousServicesNextReplica Set

Last updated 4 years ago

Was this helpful?

In production, you usually only create deployment definition yml file (no need for pod definition and replica set definition). Because deployment automatically create replicate set and pod, so you have all their benefits and extra benefit of deployment as follow:

  • Upgrade seamlessly by rolling update

  • Roll back when necessary

  • Pause, make changes and resume so that the changes are rolled out together. These changes are multiple command such as upgrading the underlying web server version and modify resource allocation. So you do not want to apply the changes immediately after each command

Deployment is higher rank than the replica set.

kubectl create -f deployment-definition.yml

kubectyl describe deployments

kubectl get deployment myapp-deployment

kubectl get all

Rollout and Versioning

When you are doing deployment, under the hood you are triggering a roll-out that create a new deployment revision (Revision 1, 2 and so on). This numbering helps us keep track of versioning and in case a roll-back is necessary.

kubectl rollout status deployment/myapp-deployment
// get status of rollout 


kubectl rollout history deployment/myapp-deployment
// info on revision and history of rollout and change-cause

There are 2 deployment strategy:

  1. Recreate - destroy all pods and then subsequently bring back all at once. Downside is application is down.

  2. Rolling update (default) - upgrading seamlessly one by one

Update your deployment

Once you make necessary changes to the definition file, run command

kubectl apply -f deployment-definition.yml 

or

kubectl set image deployment/myapp-deployment nginx-container=nginx:1.9.1
// but does not change the definition file
kubectl get replicaset
// to find out that there are 2 replicasets

kubectl rollout undo deployment/myapp-deployment
// rollback to previous revision

kubectl create -f deployment-definition.yml --record
// intialize first deployment and record the change-cause

kubectl run nginx --image=nginx command is actually not just creating pod, but create deployment. You can do deployment this way, but the recommended way is to use definition file for easier revision in the future.

Under the hood, upgrade is creating another replica set and replacing the pod one by one