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

Replica Set

PreviousDeploymentNextYAML

Last updated 4 years ago

Was this helpful?

Controller is brain behind kubernetes process that monitor kubernetes objects and respond accordingly.

The use of replica set:

  • Ensure high availability - replication controller help run multiple instances of a single pod in k8 cluster to avoid single point of failure. Does it mean we cannot have a single pod architecture? No, replication controller will bring up a new one when that single pod fails.

  • Help with load balancing and scaling by create multiple pods to share the workload across them.

The replica set can replicate another pod of the same instance inside a worker node when the user load increase or create new worker node with new pod of the same instance (meaning it can span across multiples worker nodes in the cluster)

The difference between replication controller and replica set is the former is old method and replica set is new and recommend way, even though they have the same purpose.

The most crucial part is the spec portion because it consist of three things:

  • template - replica set use this template to create pods when one goes down. This has the same content as pod-definition yml file

  • replicas - the number of replica you want to create

  • selector (mandatory) - used to identify what pods are under its control and to be monitored

The use of selector

Even though you have indicated the pod profile in the template section, the selector helps replica set to manage pod that are not created as part of replica set creation, for example, existing pod that match the labels. So when there is no existing matching pods, it will create for you.

kubectl create -f replicaset-definition.yml 
// create the replicaset based on the specification provided

kubectl get replicaset
// info about replicaset

kubectl delete replicaset myapp-replicaset 
// delete replica set and all underlying pods

kebectl delete pod ${pod name}
// delete pod

Two way to scale up or down:
1. Update yml file and run
kubectl replace -f replicaset-definition.yml

2. This way, but does not update the file automatically
kubectl scale --replicas=6 -f replicaset-definition.yml 
or
kubectl scale --replicas=6 replicaset myapp-replicaset
// replicaset is the object type
Example of replicaset-definition.yml