ReplicationController
新建一个pod_nginx.yml
apiVersion: v1kind: ReplicationControllermetadata: name: nginxspec: replicas: 3 selector: app: nginx template: metadata: name: nginx labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80
而后运行如下
kubectl create -f pod_nginx.ymlkubectl get rc
NAME | DESIRED | CURRENT | READY | AGE |
---|---|---|---|---|
nginx | 3 | 3 | 3 | 4m |
kubectl get pods
NAME | READY | STATUS | RESTARTS | AGE |
---|---|---|---|---|
nginx-89s9p | 1/1 | Running | 0 | 6m |
nginx-8bjnb | 1/1 | Running | 0 | 6m |
nginx-h49m5 | 1/1 | Running | 0 | 6m |
kubectl delete pods nginx-89s9pkubectl get podsNAME READY STATUS RESTARTS AGEnginx-2mvs9 0/1 ContainerCreating 0 <invalid>nginx-89s9p 0/1 Terminating 0 9mnginx-8bjnb 1/1 Running 0 9mnginx-h49m5 1/1 Running 0 9m
当咱们删掉一个pod的时候,kube会主动帮咱们创立另一个pod,从而达到动静的均衡
# 动静批改pod数量kubectl scale rc nginx --replicas=2
ReplicaSet
新建一个pod_nginx.yml
apiVersion: apps/v1kind: ReplicaSetmetadata: name: nginx labels: tier: frontendspec: replicas: 3 selector: matchLabels: tier: frontend template: metadata: name: nginx labels: tier: frontend spec: containers: - name: nginx image: nginx ports: - containerPort: 80
执行
# 创立kubectl create -f pod_nginx.yml# 查看kubectl get rsNAME DESIRED CURRENT READY AGEnginx 3 3 3 2m# 扩容kubectl scale rs nginx --replicas=1