通过一个实际例子理解 Kubernetes 里 pod 的自动 scale - 水平自动伸缩
kubectl scale 命令用于程序在负载加重或缩小时进行 pod 扩容或缩小,我们通过一些实际例子来观察 scale 命令到底能达到什么效果。
命令行创建一个 deployment:
kubectl get deploy 查看刚刚创建的 deployment:
自动被 deployment 创建的 pod:
kubectl get pod:
使用下列命令查看生成的 deployment 明细:
apiVersion: extensions/v1beta1kind: Deploymentmetadata:annotations:deployment.kubernetes.io/revision: "1"creationTimestamp: 2018-11-29T08:29:06Zgeneration: 1labels:run: jerry-nginxname: jerry-nginxnamespace: part-0110resourceVersion: "7203445"selfLink: /apis/extensions/v1beta1/namespaces/part-0110/deployments/jerry-nginxuid: d5c64f72-f3b0-11e8-b308-a20cb743f347spec:progressDeadlineSeconds: 600replicas: 1revisionHistoryLimit: 2selector:matchLabels:run: jerry-nginxstrategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdatetemplate:metadata:creationTimestamp: nulllabels:run: jerry-nginxspec:containers:- image: nginx:1.12.2imagePullPolicy: IfNotPresentname: jerry-nginxresources: {}terminationMessagePath: /dev/termination-logterminationMessagePolicy: FilednsPolicy: ClusterFirstrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30status:availableReplicas: 1conditions:
lastTransitionTime: 2018-11-29T08:29:07ZlastUpdateTime: 2018-11-29T08:29:07Zmessage: Deployment has minimum availability.reason: MinimumReplicasAvailablestatus: "True"type: Available
lastTransitionTime: 2018-11-29T08:29:06ZlastUpdateTime: 2018-11-29T08:29:07Zmessage: ReplicaSet "jerry-nginx-69fd9f6c4" has successfully progressed.reason: NewReplicaSetAvailablestatus: "True"type: ProgressingobservedGeneration: 1readyReplicas: 1replicas: 1updatedReplicas: 1
另一个有用的命令:
Name: jerry-nginxNamespace: part-0110CreationTimestamp: Thu, 29 Nov 2018 16:29:06 +0800Labels: run=jerry-nginxAnnotations: deployment.kubernetes.io/revision: 1Selector: run=jerry-nginxReplicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailableStrategyType: RollingUpdateMinReadySeconds: 0RollingUpdateStrategy: 25% max unavailable, 25% max surgePod Template:Labels: run=jerry-nginxContainers:jerry-nginx:Image: nginx:1.12.2Port: <none>Host Port: <none>Environment: <none>Mounts: <none>Volumes: <none>Conditions:Type Status Reason
Available True MinimumReplicasAvailableProgressing True NewReplicaSetAvailableOldReplicaSets: <none>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 进行水平扩展:
下图这个 Age 为 15 分钟之前的是第一次创建 deployment 时生成的,其他两个 Age 为 1 分钟之前的是执行了 scale 命令后自动创建的。
选中一个才创建的 pod,查看其事件记录:
得到自动创建的 replication set:
desired = 3 意思就是我们水平扩展时指定的参数 3.
即使手动删除一个 pod 实例,replication set 又会很快自动创建一个新的:
自动创建的新 pod:
要获取更多 Jerry 的原创文章,请关注公众号"汪子熙"。
版权声明: 本文为 InfoQ 作者【Jerry Wang】的原创文章。
原文链接:【http://xie.infoq.cn/article/dd31726f18366801facf6afc7】。文章转载请联系作者。
评论