# ReplicaSet

It is the component that replica the pod for `availability` and `load balance` .

**CheatSheet Command**

1. &#x20;Get ReplicaSet :  `kubectl get rs`
2. Create ReplicaSet: `kubectl apply -f <file_name>.yaml`

```yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: <replica_name>
spec:
  replicas: <numbers of replicas>
  selector:
    matchLabels:
      # this label need to match pod label for link
      <key_name>: xxx (1)      
  # this below come from Pods template    
  template:
    metadata:
      labels:
        <key_name>: xxx (2)
    spec:
      containers:
      - name: <pod_name>
        image: <image_name>

```

3. Describe information of ReplicaSet: `kubectl describe rs <replicaset_name>`
4. Delete ReplicaSet: `kubectl delete rs <replicaset_name>`
5. Edit ReplicaSet:  `kubeclt edit rs <replicaset_name>` after use this command you need to remove existing pod manually to let it recreate
6. Check the apiVersion  of the template: `kubectl explain rs`
7. Execute command from file `kubectl apply -f <file_name>.yaml`
8. Scale Pod by ReplicaSet: `kubectl scale rs --replicas=<amount_of_pod> <replicaset_name>` (It will down or create new pod automatically)
