1 introduction

1.1 concept

ReplicaSet is a new generation of ReplicationController that can completely replace RC, but it typically creates RS automatically by creating a resource such as Deployment rather than directly.

1.2 Comparison of RS and RC

1) RC’s label selector only allows matching pods that contain a tag, but RS’s selector also allows matching pods that lack a tag, or pods that contain a specific tag name. 2) RS, which is more expressive than RC, can override the selector with the matchExpressions property.

selector:
  matchExpressions:
    - key: app
      operator: In
      values:
        - app_name
Copy the code

The expression contains a list of key, operator, and values (depending on the operator) operators:

  • The value of In: Label must match one of the values specified;
  • NotIn: The value of Label does not match any specified values;
  • Exists: POD must contain a tag with a specified name. Values do not need to be specified.
  • DoesNotExist: Pod must not contain tag with specified name, values attribute must not be specified.

2. Use of RS

2.1 create RS

Write the YAML file:

  • Version number: apiVersion is apps/v1beta2
  • RS definition: KIND is ReplicaSet;
  • RS name: metadata.name
  • Number of POD instances: spec.replicas
  • Pod selector: The matchLabels selector can be used in spec.selector
  • Pod template: spec.template ** Note: RS is not part of the V1 API.

by k8s in action

Create RS command $kubectl create -f xxx.yaml

2.2 check the RS

$kubectl get RS, where RS is short for replicaset. $kubectl describe RS Rs_name

2.3 remove the RS

$kubectl delete RS rs_name