ReplicaSet的作用管理pod副本,根据配置维护指定数量的pod副本,保证其可用性。
注意 与ReplicaSet相比,Deployment/部署是一个更高层次的概念,它管理ReplicaSet并向Pod提供声明性更新以及许多其他有用的特性。官方建议使用Deployment/部署而不是直接使用ReplicaSet/副本集。
这实际上意味着你可能永远都不需要直接操作ReplicaSet对象。
示例
创建ReplicaSet(副本集)。
frontend.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
# 根据您的情况修改副本数
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google_samples/gb-frontend:v3
将此清单保存到frontend.yaml
文件,并将其提交给Kubernetes集群,Kubernetes将创建定义好的副本集和它管理的pod。
然后你可以获取当前部署的副本集:
kubectl get rs
输出
NAME DESIRED CURRENT READY AGE
frontend 3 3 3 6s
获取ReplicaSet(副本集)详情:
kubectl describe rs/frontend