一整天一整天的坐在办公室,真的很~~~,懵圈中....,求解救。
本文通过《Kubernetes权威指南》的概念部分学习总结
Deployment作用
Deployment与RC的作用其实是一样的,都是为了管理Pod的副本数
Deployment的使用场景
1)创建一个Deployment对象来生成对应的Replica Set并完成Pod副本的创建过程。
2)检查Deployment的状态来看部署动作是否完成(Pod副本的数量是否达到了预期的值)
3)更新Deployment以创建新的Pod
4)如果当前Deployment不稳定,则回滚到一个早先的Deployment版本
5)挂起或者恢复一个Deployment
例子
创建一个deployment,管理一个运行tomcat的pod
1、创建deployment.yaml文件
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: frontend spec: replicas: 1 selector: matchLabels: tier: frontend matchExpressions: - {key: tier, operator: In, values: [frontend]} template: metadata: labels: app: app-demo tier: frontend spec: containers: - name: tomcat-demo image: tomcat imagePullPolicy: IfNotPresent ports: - containerPort: 8080
2、创建deployment
[root@master ~]# kubectl create -f tomcat-deployment.yaml
deployment.extensions/frontend created
3、查看deployment信息
[root@master ~]# kubectl get deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE frontend 1 1 1 1 23s
输出结果的含义:
DESIRED:Pod副本数量的期望值,即deployment里定义的Replica
CURRENT:当前Replica的值,这个值会不断的增加,直到达到DESIRED为止,表明整个部署过程完成
UP-TO-DATE:最新版本的Pod的副本数量,用于指示在滚动升级过程中,有多少个Pod副本已经成功升级
AVAILABEL:当前集群中可用的Pod副本数量,即集群中当前存活的Pod数量
4、查看Pods信息
[root@master ~]# kubectl get pods NAME READY STATUS RESTARTS AGE frontend-6cfdb4d686-j8jj7 1/1 Running 0 9m
5、查看deployment的详细信息
[root@master ~]# kubectl describe deployment Name: frontend Namespace: default CreationTimestamp: Fri, 20 Sep 2019 06:40:40 +0000 Labels: app=app-demo tier=frontend Annotations: deployment.kubernetes.io/revision=1 Selector: tier=frontend,tier in (frontend) Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 0 RollingUpdateStrategy: 1 max unavailable, 1 max surge Pod Template: Labels: app=app-demo tier=frontend Containers: tomcat-demo: Image: tomcat Port: 8080/TCP Host Port: 0/TCP Environment: <none> Mounts: <none> Volumes: <none> Conditions: Type Status Reason ---- ------ ------ Available True MinimumReplicasAvailable Progressing True NewReplicaSetAvailable OldReplicaSets: <none> NewReplicaSet: frontend-6cfdb4d686 (1/1 replicas created) Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal ScalingReplicaSet 9m deployment-controller Scaled up replica set frontend-6cfdb4d686 to 1