ReplicaSet

    ReplicaSet 的目的是维护一组在任何时候都处于运行状态的 Pod 副本的稳定集合,可确保指定数量的pod在任何设定的时间运行。 因此,它通常用来保证给定数量的、完全相同的 Pod 的可用性。

示例

1、nginx-replicaset.yaml

[root@k8s-master k8s]# cat nginx-replicaset.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx-replicaset
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-replicaset-test
  template:
    metadata:
      labels:
        app: nginx-replicaset-test
    spec:
      containers:
      - name: nginx-replicaset-test
        image: nginx:1.20

2、创建

[root@k8s-master k8s]# kubectl create -f nginx-replicaset.yaml
replicaset.apps/nginx-replicaset created

3、查看

[root@k8s-master k8s]# kubectl get rs
NAME               DESIRED   CURRENT   READY   AGE
nginx-replicaset   3         3         3       27s

4、查看详细信息

[root@k8s-master k8s]# kubectl describe rs  nginx-replicaset
Name:         nginx-replicaset
Namespace:    default
Selector:     app=nginx-replicaset-test
Labels:       <none>
Annotations:  <none>
Replicas:     3 current / 3 desired
Pods Status:  3 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=nginx-replicaset-test
  Containers:
   nginx-replicaset-test:
    Image:        nginx:1.20
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulCreate  83s   replicaset-controller  Created pod: nginx-replicaset-8pxq7
  Normal  SuccessfulCreate  83s   replicaset-controller  Created pod: nginx-replicaset-2vl7q
  Normal  SuccessfulCreate  83s   replicaset-controller  Created pod: nginx-replicaset-bszdm

5、扩容

[root@k8s-master k8s]# kubectl scale rs nginx-replicaset --replicas=5
replicaset.apps/nginx-replicaset scaled
[root@k8s-master k8s]# kubectl get rs
NAME               DESIRED   CURRENT   READY   AGE
nginx-replicaset   5         5         5       2m47s
[root@k8s-master k8s]# kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-replicaset-2vl7q   1/1     Running   0          5m2s
nginx-replicaset-4tvmq   1/1     Running   0          2m37s
nginx-replicaset-8pxq7   1/1     Running   0          5m2s
nginx-replicaset-bszdm   1/1     Running   0          5m2s
nginx-replicaset-qksvs   1/1     Running   0          2m37s

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐