kubernetes learning record (7) - Elastic scaling and rolling upgrade

Source: Internet
Author: User
Keywords Kubernetes Rolling Upgrade Elastic Scaling Kubernetes Tutorials
Tags 192.168.1.1 app create get learning name selector test

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.