Operation Koriyuki Expansion and upgrade

Source: Internet
Author: User
Tags docker run

In this paper, we will briefly explain the expansion and upgrade of common operation and maintenance operations of kubernetes.

1.Node of expansion

Node expansion simply means adding new node nodes. Install Kubelet,kube-proxy and Docker on the node and modify the parameters to point to the master address. Based on the Kuberlet automatic registration mechanism, the new node will automatically be added to the existing Kubernetes cluster.

Dynamic expansion and scaling of 2.Pod

In the actual operations process, we often need to dynamically expand a service to meet the burst of traffic, or dynamically reduce the service instance to conserve server resources.
Below we will dynamically increase Redis-slave's pod copy from 2 to 3.
#kubectl scale RC Redis-slave–replicas=3

[[email protected] python]# Kubectl get podsNAME Ready STATUS Restartsfrontend-02x2s 1/1 Running 1 1dFrontend-8xtuj 1/1 Running 1 1dfrontend-ko8b2 1/1 Running 1 1dredis-master-2v6pp 1/1 Running 1 1dredis-slave-5k126 1/1 Running 1 1dredis-slave-9dqti 1/1 Running 1 1d [email protected] python]# kubectl scale RC Redis-slave--replicas=3 scaled
[[email protected] python]# kubectl get podsname                 ready     STATUS    restarts   agefrontend-02x2s       1/1       Running   1          1dfrontend-8xtuj       1/1       Running   1 &nbsp ;        1DFRONTEND-KO8B2       1/1       Running   1     & nbsp    1dredis-master-2v6pp   1/1       Running   1          1dred is-slave-0d33n    1/1       Running   0          59SREDIS-SLAVE-5K1    1/1       Running   1          1DREDIS-SLAVE-9DQTI   &NB SP;1/1       Running   1          1D

The same we can reduce the pod copy, below we will redis-slave from 3 copies to 1.

[email protected] python]# kubectl scale RC Redis-slave--replicas=1Scaled[[email protected] python]# Kubectl get podsname ready STATUS restarts agefrontend-02x2s 1/ 1 Running 1 1dfrontend-8xtuj 1/1 Running 1 1dfrontend-ko8b2 1/1 Runnin          G 1 1dredis-master-2v6pp 1/1 Running 1 1dredis-slave-0d33n 1/1 Running 0 2M3. Rolling Upgrades for apps

In the actual operations process, how to upgrade without stopping the service will become more and more common, Kubernetes provides the rolling-update function to solve the above scenario.
We assume that PHP's image has a new V2 version, and we need to upgrade the existing PHP service to v2.

3.1 Making a new image

For simplicity, we make a new image with Docker commit, first starting a new container with the original image, you can modify it in the container, and then exit.

[email protected] python]# Docker run-it Docker.io/kubeguide/guestbook-php-frontend/bin/bash
[Email protected]:/var/www/html# exit
Exit Okay, now we're going to use Docker commit to save the container we just edited, and we'll name it guestbook-php-frontend:v2.
[email protected] python]# Docker commit 68b765a2b8db guestbook-php-frontend:v2afa8c93501405642879a30d14ddeb087e48d8fb7a7a04dd2ab8f5556fd9db99b[email protected] python]# Docker imagesREPOSITORY TAG IMAGE ID CREATED VIR Tual SIZEguestbook-php-frontend v2 afa8c9350140 about a minute ago 509 .6 MBDaocloud.io/daocloud/daocloud-toolset latest 01869b5aa54e 3 weeks ago 150 .2 MBDocker.io/mysql latest 4b95c7a7999d 4 weeks ago 374 MBregistry.access.redhat.com/rhel7/pod-infrastructure latest 2b96d2bcbc46 6 weeks ago 428 MBdocker.io/kubeguide/guestbook-php-frontend latest 38658844a359 8 months ago 509 .6 MBDocker.io/kubeguide/redis-master latest 423e126c2ad4 8 months ago 419 .1 MBDocker.io/kubeguide/guestbook-redis-slave Latest 00206e07dd92 9 months ago 109 .5 MBWe see a new addition to the image Guestbook-php-frontend,tag for V2, and then we'll demonstrate the rolling upgrade in two ways. 3.2 Through configuration files

Create Frontend-controller-v2.yaml

apiVersion: v1kind: ReplicationControllermetadata:  name: frontend-v2  labels:    name: frontendspec:  replicas: 3  selector:    name: frontend-v2  template:    metadata:      labels:        name: frontend-v2    spec:      containers:      - name: php-redis        image: guestbook-php-frontend:v2        env:        - name: GET_HOSTS_FROM          value: env        ports:        - containerPort: 80

The KUBECTL is executed as follows:

[email protected] kube-guestbook]#Kubectl rolling-update frontend-f Frontend-controller-v2.yaml View the pods creation process, we see a new pod copy increased from 1, and the old pod copy is progressively reduced from 3, The final old pod copy is deleted. This completes the upgrade of the application. 3.3 With new image

Another method is to use the Kubectl rolling-update plus –image parameter to specify the new image name to scroll the upgrade without using a configuration file
Kubectl rolling-update Frontend–image=guestbook-php-frontend:v2

After the update is complete, view RC, we see the same as the configuration file, Kubectl to RC added a key to "deployment" the label, of course, the name can be modified by –deployment-label-key parameters.

[[email protected] ~]# kubectl get rcCONTROLLER     CONTAINER(S)   IMAGE(S)                                    SELECTOR                                                    REPLICASfrontend       php-redis      guestbook-php-frontend:v2                   deployment=cdb7f26e49a90eae43e257284310b1cf,name=frontend   3

If a configuration error is found during the update process, you can complete the rollback by performing Kubectl Rolling-update–rollback
Kubectl rolling-update Frontend–image=guestbook-php-frontend:v2–rollback

Operation Koriyuki Expansion and upgrade

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.