ReplicaSet
Overview
- ReplicaSet is a process of monitoring pods, when pod is down, it will startup a new one.
- ReplicaSet identify which pods to monitor by labels.
- RelicatSet monitor and keep the pod number as described in yaml file or command line setting. In order word, if part of the pods is down, ReplicaSet will automatically start new pods to keep the pod number as described in ReplicaSet yaml.
- According to #2 and #3, suppose that there is a number of pods running as described in ReplicaSet yaml. We start a new pod with the same label described in RelipcaSet in some way, (e.g. start a new pod by pod.yaml), the newly created pod will be terminated since ReplicaSet will keep the pod number by labels described in ReplicaSet yaml.
Yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: my-rc
labels:
app: myapp
type: front-end
spec:
# RelicaSet - template - pod description
# RelicaSet - replicas - pod number
# RelicaSet - selector - pod finder
replicas: 3
selector: # match the pod label @1
matchLabels:
type: front-end
template:
metadata:
labels: # pod label @1
type: front-end
spec:
containers:
- name: ngx-container
image: nginx
Test
kubectl apply -f replicaset.yaml
kubectl describe pod ngx-container
kubectl apply -f replicaset.yaml # change replicas from 3 to 5.
kubectl get pods
kubectl delete -f replicaset.yaml
分类:
k8s
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下