公网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. 1.创建
  2. kubectl run nginx --replicas=3 --image=nginx:1.14 --port=80
  3. kubectl get deploy,pods
  4. 2.发布(暴露)
  5. kubectl expose deployment nginx --port=80 --type=NodePort --target-port=80 --name=nginx-service
  6. kubectl get service
  7. [root@instance-fq0043cl-3 ~]# kubectl get service
  8. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  9. kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 112d
  10. nginx NodePort 10.110.204.160 <none> 80:30179/TCP 110d
  11. nginx-cmdb NodePort 10.110.204.170 <none> 81:30180/TCP 109d
  12. nginx-service NodePort 10.110.91.64 <none> 80:32003/TCP 3s
  13. #浏览器访问任意node的公网ip+32003,即可访问刚才创建nginx
  14. 3.更新
  15. kubectl set image deployment/nginx nginx=nginx:1.15
  16. #查看镜像的信息是否是1.14
  17. [root@instance-fq0043cl-3 ~]# kubectl describe pod nginx-w-997f65bb9-5sxcz
  18. [root@instance-fq0043cl-3 ~]# kubectl set image deployment/nginx nginx=nginx:1.15
  19. deployment.extensions/nginx image updated
  20. #k8s不会立即所有的立刻更新,会一个个容器的更新.
  21. 4.回滚
  22. #查看所有的历史更新
  23. kubectl rollout history deployment/nginx
  24. #undo直接回滚上一个版本
  25. kubectl rollout undo deployment/nginx
  26. 5.删除
  27. kubectl delete deploy/nginx
  28. kubectl delete svc/nginx-service