公网ip |
内网eth0 ip |
角色 |
系统版本 |
180.76.150.184 |
172.18.0.111 |
master |
CentOS 7.3.1611 (Core) |
180.76.114.227 |
172.18.0.109 |
node1 |
CentOS 7.3.1611 (Core) |
180.76.164.183 |
172.18.0.110 |
node2 |
CentOS 7.3.1611 (Core) |
管理应用程序生命周期 master执行
1.创建
kubectl run nginx --replicas=3 --image=nginx:1.14 --port=80
kubectl get deploy,pods
2.发布(暴露)
kubectl expose deployment nginx --port=80 --type=NodePort --target-port=80 --name=nginx-service
kubectl get service
[root@instance-fq0043cl-3 ~]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 112d
nginx NodePort 10.110.204.160 <none> 80:30179/TCP 110d
nginx-cmdb NodePort 10.110.204.170 <none> 81:30180/TCP 109d
nginx-service NodePort 10.110.91.64 <none> 80:32003/TCP 3s
#浏览器访问任意node的公网ip+32003,即可访问刚才创建nginx
3.更新
kubectl set image deployment/nginx nginx=nginx:1.15
#查看镜像的信息是否是1.14
[root@instance-fq0043cl-3 ~]# kubectl describe pod nginx-w-997f65bb9-5sxcz
[root@instance-fq0043cl-3 ~]# kubectl set image deployment/nginx nginx=nginx:1.15
deployment.extensions/nginx image updated
#k8s不会立即所有的立刻更新,会一个个容器的更新.
4.回滚
#查看所有的历史更新
kubectl rollout history deployment/nginx
#undo直接回滚上一个版本
kubectl rollout undo deployment/nginx
5.删除
kubectl delete deploy/nginx
kubectl delete svc/nginx-service