美文网首页
kubectl命令实践(4) --- 部署管理

kubectl命令实践(4) --- 部署管理

作者: 糖can果 | 来源:发表于2018-10-28 21:47 被阅读0次
    命令 解释
    kubectl scale 实现水平扩展或收缩
    kubectl rollout status 部署状态变更,状态检查
    kubectl rollout history 部署的历史
    kubectl rollout undo 回滚部署到最近或者某个版本

    实际操作:

    1. 执行命令: kubectl scale deployment nginx  --replicas=3
    
    deployment.extensions/nginx scaled
    
    2.执行命令:kubectl get deployments
    
    NAME    DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
    nginx   3         3         3            3           50m
    
    3.kubectl describe rs nginx-65899c769f
    
    Name:           nginx-65899c769f
    Namespace:      default
    Selector:       pod-template-hash=2145573259,run=nginx
    Labels:         pod-template-hash=2145573259
                    run=nginx
    Annotations:    deployment.kubernetes.io/desired-replicas: 3
                    deployment.kubernetes.io/max-replicas: 4
                    deployment.kubernetes.io/revision: 1
    Controlled By:  Deployment/nginx
    Replicas:       3 current / 3 desired
    Pods Status:    3 Running / 0 Waiting / 0 Succeeded / 0 Failed
    Pod Template:
      Labels:  pod-template-hash=2145573259
               run=nginx
      Containers:
       nginx:
        Image:        nginx
        Port:         <none>
        Host Port:    <none>
        Environment:  <none>
        Mounts:       <none>
      Volumes:        <none>
    Events:
      Type    Reason            Age   From                   Message
      ----    ------            ----  ----                   -------
      Normal  SuccessfulCreate  51m   replicaset-controller  Created pod: nginx-65899c769f-qjlfj
      Normal  SuccessfulCreate  2m6s  replicaset-controller  Created pod: nginx-65899c769f-qptcl
      Normal  SuccessfulCreate  2m6s  replicaset-controller  Created pod: nginx-65899c769f-6pzwn
    
    4. kubectl get pods
    NAME                     READY   STATUS    RESTARTS   AGE
    nginx-65899c769f-6pzwn   1/1     Running   0          3m
    nginx-65899c769f-qjlfj   1/1     Running   0          52m
    nginx-65899c769f-qptcl   1/1     Running   0          3m
    
    5.kubectl describe services nginx
    Name:                     nginx
    Namespace:                default
    Labels:                   app=nginx
    Annotations:              <none>
    Selector:                 run=nginx
    Type:                     NodePort
    IP:                       10.102.111.71
    Port:                     http  8888/TCP
    TargetPort:               80/TCP
    NodePort:                 http  30001/TCP
    Endpoints:                172.17.0.5:80,172.17.0.6:80,172.17.0.7:80
    Session Affinity:         None
    External Traffic Policy:  Cluster
    Events:                   <none>
    
    5.kubectl get endpoints 
    NAME         ENDPOINTS                                   AGE
    kubernetes   192.168.99.100:8443                         23h
    nginx        172.17.0.5:80,172.17.0.6:80,172.17.0.7:80   20m
    nginx-wls    172.17.0.5:80,172.17.0.6:80,172.17.0.7:80   9m
    
    6. kubectl get pods
    NAME                     READY   STATUS        RESTARTS   AGE
    nginx-65899c769f-6pzwn   0/1     Terminating   0          6m
    nginx-65899c769f-qjlfj   1/1     Running       0          56m
    nginx-65899c769f-qptcl   1/1     Running       0          6m
    [root@wls yaml]# kubectl get pods
    NAME                     READY   STATUS    RESTARTS   AGE
    nginx-65899c769f-qjlfj   1/1     Running   0          56m
    nginx-65899c769f-qptcl   1/1     Running   0          6m
    
    7. kubectl set image deploy nginx nginx=nginx:1.9.1
    deployment.extensions/nginx image updated
    
    8.  kubectl rollout history deployment nginx 
    deployment.extensions/nginx 
    REVISION  CHANGE-CAUSE
    1         <none>
    2         <none>
    
    9.kubectl describe deployments nginx
    
    Name:                   nginx
    Namespace:              default
    CreationTimestamp:      Sun, 28 Oct 2018 21:46:00 +0800
    Labels:                 run=nginx
    Annotations:            deployment.kubernetes.io/revision: 2
    Selector:               run=nginx
    Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
    StrategyType:           RollingUpdate
    MinReadySeconds:        0
    RollingUpdateStrategy:  25% max unavailable, 25% max surge
    Pod Template:
      Labels:  run=nginx
      Containers:
       nginx:
        Image:        nginx:1.9.1
        Port:         <none>
        Host Port:    <none>
        Environment:  <none>
        Mounts:       <none>
      Volumes:        <none>
    Conditions:
      Type           Status  Reason
      ----           ------  ------
      Available      True    MinimumReplicasAvailable
      Progressing    True    NewReplicaSetAvailable
    OldReplicaSets:  <none>
    NewReplicaSet:   nginx-76bc854778 (2/2 replicas created)
    Events:
      Type    Reason             Age    From                   Message
      ----    ------             ----   ----                   -------
      Normal  ScalingReplicaSet  11m    deployment-controller  Scaled up replica set nginx-65899c769f to 3
      Normal  ScalingReplicaSet  5m19s  deployment-controller  Scaled down replica set nginx-65899c769f to 2
      Normal  ScalingReplicaSet  70s    deployment-controller  Scaled up replica set nginx-76bc854778 to 1
      Normal  ScalingReplicaSet  30s    deployment-controller  Scaled down replica set nginx-65899c769f to 1
      Normal  ScalingReplicaSet  30s    deployment-controller  Scaled up replica set nginx-76bc854778 to 2
      Normal  ScalingReplicaSet  24s    deployment-controller  Scaled down replica set nginx-65899c769f to 0
    
    11. kubectl rollout undo deployment nginx   回滚
          deployment.extensions/nginx
    
    
    
    
    

    相关文章

      网友评论

          本文标题:kubectl命令实践(4) --- 部署管理

          本文链接:https://www.haomeiwen.com/subject/zkwmtqtx.html