- ReplicationController 配置文件
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
spec:
# 横向扩展3个
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
- 删除某个pod,指定名称
kubectl delete pods nginx-2mjbb
删除之后,它会自动创建一个新的来维持我们设置的数量
- 修改横向扩展的数量
kubectl scale rc nginx --replicas=2
- ReplicaSet 配置文件
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状态
kubectl get rs
- 横向扩展数量
kubectl scale rs nginx --replicas=2