> For the complete documentation index, see [llms.txt](https://moluo.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://moluo.gitbook.io/notes/bian-cheng-xue-xi/bu-shu-yun-wei-xu-ni-hua/kubernetes/4.replicaset-he-replicationcontroller.md).

# 4.Replicaset和ReplicationController

kubectl create -f {rs yam fille | rc yam fille}

rs\_nginx.yml

```yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx
  labels:
    tier: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      tier: frontend
  template:
    metadata:
      name: nginx
      labels:
        tier: frontend
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
```

> 注意：新版本才支持Replicaset，相比ReplicationController，Replicaset支持new set-based selector

查看Replicaset：kubectl get rs

横向扩展pod数：kubectl scale rs {rs name} --replicas={pod 数}

```yaml
apiVersion: v1
kind: ReplicationController 
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    app: nginx
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
```

查看ReplicationController：kubectl get rc

删除ReplicationController：kubectl delete -f {rc yaml file}

横向扩展pod数：kubectl scale rc {rc name} --replicas={pod 数}
