kubernetes中的deployment模拟failover

先写了个简单的应用部署,副本设置为5
[[email protected] ~]$ cat nginx.yml 
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 5
template:
metadata:
labels:
app: web_server
spec:
containers:
- name: nginx
image: nginx:1.7.9
[[email protected] ~]$
然后开始部署应用
[[email protected] ~]$ kubectl apply -f nginx.yml 
deployment.extensions/nginx-deployment configured
[[email protected] ~]$ kubectl get pod
NAME READY STATUS RESTARTS AGE
http-app-5b7568bf86-bnszg 1/1 Running 0 106m
http-app-5b7568bf86-vwtl6 1/1 Running 0 106m
myjob-2q7tk 0/1 Completed 0 52d
myjob-4gbwc 0/1 Completed 0 52d
myjob-bpw87 0/1 Completed 0 52d
myjob-lmbbv 0/1 Completed 0 52d
myjob-s6s7j 0/1 Completed 0 52d
myjob-zz9fx 0/1 Completed 0 52d
nginx-deployment-656d6ccbd5-2nc6m 1/1 Running 0 3s
nginx-deployment-656d6ccbd5-hr5ff 1/1 Running 0 98s
nginx-deployment-656d6ccbd5-k8lbj 1/1 Running 0 98s
nginx-deployment-656d6ccbd5-rmkz6 1/1 Running 0 3s
nginx-deployment-656d6ccbd5-sd4ss 1/1 Running 0 98s
查看详细属性
[[email protected] ~]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-app-5b7568bf86-bnszg 1/1 Running 0 111m 10.244.1.20 k8s-node1 <none> <none>
http-app-5b7568bf86-vwtl6 1/1 Running 0 111m 10.244.3.14 k8s-node3 <none> <none>
myjob-2q7tk 0/1 Completed 0 52d 10.244.2.11 k8s-node2 <none> <none>
myjob-4gbwc 0/1 Completed 0 52d 10.244.3.12 k8s-node3 <none> <none>
myjob-bpw87 0/1 Completed 0 52d 10.244.3.13 k8s-node3 <none> <none>
myjob-lmbbv 0/1 Completed 0 52d 10.244.1.19 k8s-node1 <none> <none>
myjob-s6s7j 0/1 Completed 0 52d 10.244.2.12 k8s-node2 <none> <none>
myjob-zz9fx 0/1 Completed 0 52d 10.244.1.18 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-2nc6m 1/1 Running 0 5m43s 10.244.1.24 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-hr5ff 1/1 Running 0 7m18s 10.244.1.23 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-k8lbj 1/1 Running 0 7m18s 10.244.3.17 k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-rmkz6 1/1 Running 0 5m43s 10.244.2.16 k8s-node2 <none> <none>
nginx-deployment-656d6ccbd5-sd4ss 1/1 Running 0 7m18s 10.244.2.15 k8s-node2 <none> <none>
过了一会
[[email protected] ~]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-app-5b7568bf86-bnszg 1/1 Running 0 113m 10.244.1.20 k8s-node1 <none> <none>
http-app-5b7568bf86-vwtl6 1/1 Running 0 113m 10.244.3.14 k8s-node3 <none> <none>
myjob-4gbwc 0/1 Completed 0 52d 10.244.3.12 k8s-node3 <none> <none>
myjob-bpw87 0/1 Completed 0 52d 10.244.3.13 k8s-node3 <none> <none>
myjob-lmbbv 0/1 Completed 0 52d 10.244.1.19 k8s-node1 <none> <none>
myjob-zz9fx 0/1 Completed 0 52d 10.244.1.18 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-2nc6m 1/1 Running 0 7m11s 10.244.1.24 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-8ckzb 1/1 Running 0 18s 10.244.3.18 k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-hr5ff 1/1 Running 0 8m46s 10.244.1.23 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-j88pc 1/1 Running 0 18s 10.244.1.25 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-k8lbj 1/1 Running 0 8m46s 10.244.3.17 k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-rmkz6 1/1 Terminating 0 7m11s 10.244.2.16 k8s-node2 <none> <none>
nginx-deployment-656d6ccbd5-sd4ss 1/1 Terminating 0 8m46s 10.244.2.15 k8s-node2 <none> <none>
同时确认node2下线
[[email protected] ~]$ kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 52d v1.14.2
k8s-node1 Ready <none> 52d v1.14.2
k8s-node2 NotReady <none> 52d v1.14.2
k8s-node3 Ready <none> 52d v1.14.2
Node2重新开机
[[email protected] ~]$ kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 52d v1.14.2
k8s-node1 Ready <none> 52d v1.14.2
k8s-node2 Ready <none> 52d v1.14.2
k8s-node3 Ready <none> 52d v1.14.2
再次查看pod,可以发现原来状态为terminating的pod已经删除,但是已有的pod不会重新调度回去
[[email protected] ~]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-app-5b7568bf86-bnszg 1/1 Running 0 115m 10.244.1.20 k8s-node1 <none> <none>
http-app-5b7568bf86-vwtl6 1/1 Running 0 115m 10.244.3.14 k8s-node3 <none> <none>
myjob-4gbwc 0/1 Completed 0 52d 10.244.3.12 k8s-node3 <none> <none>
myjob-bpw87 0/1 Completed 0 52d 10.244.3.13 k8s-node3 <none> <none>
myjob-lmbbv 0/1 Completed 0 52d 10.244.1.19 k8s-node1 <none> <none>
myjob-zz9fx 0/1 Completed 0 52d 10.244.1.18 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-2nc6m 1/1 Running 0 9m47s 10.244.1.24 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-8ckzb 1/1 Running 0 2m54s 10.244.3.18 k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-hr5ff 1/1 Running 0 11m 10.244.1.23 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-j88pc 1/1 Running 0 2m54s 10.244.1.25 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-k8lbj 1/1 Running 0 11m 10.244.3.17 k8s-node3 <none> <none>
此条目发表在kubernetes分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注