The kubectl scale command is used to expand or shrink pod when the load increases or shrinks. Let’s look at some practical examples to see what the scale command can achieve.
Create a deployment command line:
Kubectl run jerry - nginx - image = nginx: 1.12.2Copy the code
Kubectl get deploy check the deployment that you just created:
Pod automatically created by Deployment:
kubectl get pod:
Use the following command to view the generated Deployment details:
kubectl get deployment jerry-nginx -o yamlCopy the code
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"Copy the code
creationTimestamp: 2018-11-29T08:29:06Z
generation: 1
labels:
run: jerry-nginxCopy the code
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-nginxCopy the code
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdateCopy the code
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: 30Copy the code
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
Another useful command:
kubectl describe deployment jerry-nginxCopy the code
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: <none> Host Port: <none> Environment: <none> Mounts: <none> MountsCopy the code
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
Now we scale deployment horizontally with the following command:
kubectl scale deployment jerry-nginx --replicas=3Copy the code
kubectl get pods -l run=jerry-nginxCopy the code
The Age in the figure below is 15 minutes old and was generated when the deployment was first created, and the other two ages are 1 minute old and created automatically after the scale command was executed.
Select a newly created POD and view its event log:
kubectl describe pod jerry-nginx-69fd9f6c4-8dpvbCopy the code
kubectl get replicasetCopy the code
Get the automatically created replication set:
Desired = 3 means that we specify parameter 3 when we extend horizontally.
Even if a POD instance is manually deleted, the Replication set will soon automatically create a new one:
New pods automatically created:
This article is from “Wang Zixi”, a partner of the cloud habitat community. For relevant information, you can follow the wechat public account “Wang Zixi”.