前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >通过一个实际例子理解Kubernetes里pod的自动scale - 水平自动伸缩

通过一个实际例子理解Kubernetes里pod的自动scale - 水平自动伸缩

作者头像
Jerry Wang
发布2019-06-02 00:52:17
4410
发布2019-06-02 00:52:17
举报

kubectl scale命令用于程序在负载加重或缩小时进行pod扩容或缩小,我们通过一些实际例子来观察scale命令到底能达到什么效果。

命令行创建一个deployment:

代码语言:javascript
复制
kubectl run jerry-nginx --image=nginx:1.12.2

kubectl get deploy查看刚刚创建的deployment:

自动被deployment创建的pod:

kubectl get pod:

使用下列命令查看生成的deployment明细:

代码语言:javascript
复制
kubectl get deployment jerry-nginx -o yaml

apiVersion: extensions/v1beta1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: “1” creationTimestamp: 2018-11-29T08:29:06Z generation: 1 labels: run: jerry-nginx name: jerry-nginx namespace: part-0110 resourceVersion: “7203445” selfLink: /apis/extensions/v1beta1/namespaces/part-0110/deployments/jerry-nginx uid: d5c64f72-f3b0-11e8-b308-a20cb743f347 spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 2 selector: matchLabels: run: jerry-nginx strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: run: jerry-nginx spec: containers: - image: nginx:1.12.2 imagePullPolicy: IfNotPresent name: jerry-nginx resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 status: availableReplicas: 1 conditions:

  • lastTransitionTime: 2018-11-29T08:29:07Z lastUpdateTime: 2018-11-29T08:29:07Z message: Deployment has minimum availability. reason: MinimumReplicasAvailable status: “True” type: Available
  • lastTransitionTime: 2018-11-29T08:29:06Z lastUpdateTime: 2018-11-29T08:29:07Z message: ReplicaSet “jerry-nginx-69fd9f6c4” has successfully progressed. reason: NewReplicaSetAvailable status: “True” type: Progressing observedGeneration: 1 readyReplicas: 1 replicas: 1 updatedReplicas: 1

另一个有用的命令:

代码语言:javascript
复制
kubectl describe deployment jerry-nginx

Name: jerry-nginx Namespace: part-0110 CreationTimestamp: Thu, 29 Nov 2018 16:29:06 +0800 Labels: run=jerry-nginx Annotations: deployment.kubernetes.io/revision: 1 Selector: run=jerry-nginx Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 0 RollingUpdateStrategy: 25% max unavailable, 25% max surge Pod Template: Labels: run=jerry-nginx Containers: jerry-nginx: Image: nginx:1.12.2 Port: Host Port: Environment: Mounts: Volumes: Conditions: Type Status Reason


Available True MinimumReplicasAvailable Progressing True NewReplicaSetAvailable OldReplicaSets: NewReplicaSet: jerry-nginx-69fd9f6c4 (1/1 replicas created) Events: Type Reason Age From Message


Normal ScalingReplicaSet 9m41s deployment-controller Scaled up replica set jerry-nginx-69fd9f6c4 to 1

现在我们使用下面的命令对deployment进行水平扩展:

代码语言:javascript
复制
kubectl scale deployment jerry-nginx --replicas=3
代码语言:javascript
复制
kubectl get pods -l run=jerry-nginx

下图这个Age为15分钟之前的是第一次创建deployment时生成的,其他两个Age为1分钟之前的是执行了scale命令后自动创建的。

选中一个才创建的pod,查看其事件记录:

代码语言:javascript
复制
kubectl describe pod jerry-nginx-69fd9f6c4-8dpvb
代码语言:javascript
复制
kubectl get replicaset
```sd

得到自动创建的replication set:
![](http://upload-images.jianshu.io/upload_images/2085791-45813c64aa3268be.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


desired = 3意思就是我们水平扩展时指定的参数3.

即使手动删除一个pod实例,replication set又会很快自动创建一个新的:
![](http://upload-images.jianshu.io/upload_images/2085791-834fe8ffcc36a8d1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


自动创建的新pod:
![](http://upload-images.jianshu.io/upload_images/2085791-c9aae3be6cf247cc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

![](https://upload-images.jianshu.io/upload_images/2085791-dcc88e58a67cac8c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年11月30日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档