kubernetes learning record (7) - Elastic scaling and rolling upgrade.
Elastic telescopic
Elastic scaling refers to adapting to load changes and providing resources in a flexible and scalable way.
Pod's flexible scaling is to modify the number of Replica Replicator Controller. Can be achieved through the Kubectl scale command.
Create a Replication Controller
test-rc.yaml
apiVersion: v1 kind: ReplicationController metadata: name: test-rc spec: replicas: 2 selector: app: test template: metadata: labels: app: test spec: containers: 192.168.121.143:5000/busybox imagePullPolicy: IfNotPresent restartPolicy: Always
Create RC
# kubectl create -f test-rc.yaml
View created pods
# kubectl get pod --selector app = test -o wide
Expand the number of pods to 4 # kubectl scale rc test-rc --replicas = 4 # kubectl get pod --selector app = test -o wide
Shrink pods to 1 # kubectl scale rc test-rc --replicas = 1 # kubectl get pod --selector app = test -o wide
By setting the number of pods to 0, all pods associated with the RC can be deleted.
Rolling upgrade
Rolling upgrade using gradual replacement strategy.
Through an example to demonstrate, demo applications from V1 version to V2 version.
Create V1 version of RC.
my-app-v1-rc.yaml
apiVersion: v1 kind: ReplicationController metadata: name: myapp-v1 spec: replicas: 10 selector: app: myapp version: v1 template: metadata: labels: app: myapp version: v1 spec: containers: - name: myapp command: - sleep - "3600" image: 192.168.121.143:5000/busybox:v1 imagePullPolicy: IfNotPresent restartPolicy: Always
Create RC, view RC and Pod.
# kubectl create -f my-app-v1-rc.yaml # kubectl get rc myapp-v1 -o wide # kubectl get pods --selector app = myapp -o wide
Create a V2 version of RC.
my-app-v2-rc.yaml
apiVersion: v1 kind: ReplicationController metadata: name: myapp-v2 spec: replicas: 10 selector: app: myapp version: v2 template: metadata: labels: app: myapp version: v2 spec: containers: - name: myapp command: - sleep - "3600" image: 192.168.121.143:5000/busybox:v2 imagePullPolicy: IfNotPresent restartPolicy: Always
Start rolling upgrade
# kubectl rolling-update myapp-v1 -f my-app-v2-rc.yaml --update-period = 10s
Use -update -period = 10s to set the number of copies of RC that incrementally increase the version V2 of RC every 10 seconds and gradually reduce the number of copies of RC for version V1.
After the upgrade is complete, remove the V1 version of the RC, keep the V2 version of the RC.
During the upgrade, you can roll back. If the upgrade is complete, you can not use this command to roll back.
# kubectl rolling-update myapp-v1 -f my-app-v2-rc.yaml --update-period = 10s --rollback