• 周六. 7 月 13th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

K8s learning notes (3) – kubectl high availability deployment, capacity expansion, upgrade, rollback

King Wang

1 月 29, 2022

Preface : The last one passed rancher management k8s, Deployment service application expansion , High availability , This paper introduces kubectl Deploy highly available cluster nodes from the command line , Test upgrade 、 Expansion, etc

1、 Test environment :3 node k3s, Use among them 2 node (ubuntunode1 And ubuntunode2),node3 Not for the time being

  • Enter the command , View node status

    image

2、 Enter any node , Use kubectl Use the command line to deploy the service , We use node1 node

  • Create a new one .yaml file , Used to deploy 2 A load of applications , File name :springbootapp-2nodes.yaml

    image

  • The contents of the document are as follows ,kind Node usage Deployment type :

    image

  • The text is as follows :
     apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: springbootapp-dep
    labels:
    app: springbootapp
    spec:
    replicas: 2
    selector:
    matchLabels:
    app: springbootapp
    template:
    metadata:
    labels:
    app: springbootapp
    spec:
    containers:
    - name: springbootapp
    image: xjk27400861/springbootapp:42
    ports:
    - containerPort: 8080
    
  • Create a new namespace , Used to deploy clustered applications
    The order is as follows :
     sudo kubectl create namespace springboot2node
    

    image

  • Enter the command , establish 2 Node copy application ,-n Specify the namespace
    The order is as follows :
     sudo kubectl create -f springbootapp-2nodes.yaml -n springboot2node
    

    image

  • It can also be in .yaml Specifies the namespace in the file :

    image

  • Enter the command , see pod Node running state
    The order is as follows :
     sudo kubectl get pods -n springboot2node
    

    image

  • Enter the command , View the replica set
    The order is as follows :
     sudo kubectl get rs -n springboot2node
    

    image

  • Enter the command , Create a svc Of service, Exposure cluster
    The order is as follows :
     sudo kubectl apply -f springbootapp-2node-svc.yaml
    

    image

  • springbootapp-2node-svc.yaml The contents of the document are as follows :
     apiVersion: v1
    kind: Service
    metadata:
    name: springbootapp-2node-svc
    namespace: springboot2node
    labels:
    app: springbootapp-2node-svc
    spec:
    type: NodePort
    ports:
    - port: 8080
    nodePort: 30001
    selector:
    app: springbootapp
    

    image

  • Through any node ip+ port :30001+ Route to access the application , I am :http://192.168.231.133:30001/hello or http://192.168.231.134:30001/hello

    image

3、k8s Capacity expansion

  • Modify the configuration file springbootapp-2nodes.yaml,2 The node is changed to 3 node

    image

  • Enter the command , Redeployment , View the replica set to 3 individual
     sudo kubectl apply -f springbootapp-2nodes.yaml --record=true
    

    image

  • see pod Number , Also for the 3 individual

    image

4、k8s Self healing

  • Delete 2 individual pod, Simulate server downtime
     sudo kubectl delete pod springbootapp-dep-67656f6dc9-cncb6 springbootapp-dep-67656f6dc9-pp47x -n springboot2node
    

    image

  • Review pod condition , Found it rebuilt 2 A new one pod, Guaranteed load or 3 platform
     sudo kubectl get pods -n springboot2node
    

    image

5、k8s upgrade

  • Modify the code , Differentiate versions , Rebuild the image and push it to the warehouse

    image

  • New image tag:43

    image

  • Modify the deployment file :springbootapp-2nodes.yaml, The image version is changed to 43

    image

  • Enter the command , Re deploy the application , Parameters –record=true Give Way Kubernetes Record this line of command in the release history for later viewing
     sudo kubectl apply -f springbootapp-2nodes.yaml --record=true
    

    image

  • ContainerCreating The status indicates that the new version of the container is starting ,Running Yes, the new version is already running ,Terminating This is an old version of and is stopping
  • After a while , Find out 3 Nodes have been created

    image

  • To access the application , You can see that the new version has been released

    image

6、k8s Roll back application

  • Enter the command , View release history
     sudo kubectl rollout history deployment springbootapp-dep -n springboot2node
    

    image

  • You can see that there is 2 A version , We roll back to version 1 The state of
     sudo kubectl rollout undo deployment springbootapp-dep --to-revision=1 -n springboot2node
    
  • View rollback status , success
     sudo kubectl rollout status deployment springbootapp-dep -n springboot2node
    

    image

  • To access the application , You can see that the application has been rolled back to the old version

    image

7、rancher2.x Yes springboot2node Migration , Migrate to default Under the project , Easy rancher management

image

  • image
    image

  • Namespace has been transferred to project default in

    image

  • You can go through rancher Operation application capacity expansion, capacity reduction, rollback, etc , It will be quite convenient

    image

发表回复