当前位置:网站首页>3-1. Pod controller
3-1. Pod controller
2022-04-21 07:11:00 【smile_ pbb】
One 、Pod Controller Introduction
stay kubernetes in , according to pod Can be divided into two categories :
Autonomous pod:kubernetes Created directly Pod, such pod After deleting it, it's gone , It won't rebuild
Created by controller pod:kubernetes Created by the controller pod, such pod After deletion, it will be rebuilt automatically
1.Pod controller
Pod The controller is the manager pod The middle tier , Use Pod After the controller , Just tell Pod controller , How many and what kind of Pod That's all right. , It will create a that meets the conditions Pod And ensure that every Pod The resource is in the desired target state . If Pod The resource failed while running , It will be rearranged based on the specified policy Pod.
2.Pod Controller type
| Controller type | effect |
|---|---|
| ReplicaSet | Ensure that the number of copies is maintained at the desired value , And support pod Quantity expansion and contraction capacity , Mirror version upgrade |
| Deployment | By controlling ReplicaSet To control Pod, And support rolling upgrade 、 Rollback version |
| Horizontal Pod Autoscaler | It can be adjusted automatically according to the cluster load level Pod The number of , To cut peak and fill valley |
| DaemonSet | Specified in the cluster Node Run on and only one copy , Generally used for tasks of daemon classes |
| Job | It created pod Quit as soon as you finish the task , There is no need to reboot or rebuild , Used to perform one-time tasks |
| Cronjob | It creates Pod Responsible for periodic task control , You don't need to keep running in the background |
| StatefulSet | Manage stateful applications |
Two 、ReplicaSet(RS)
ReplicaSet The main function of Guarantee a certain amount of pod The normal operation , It will continue to monitor these Pod Operating state , once Pod failure , Will restart or rebuild . It also supports pod The amount of expansion and reduction and the upgrade and downgrade of the image version .
[root@t3-tkhijbs-jcsszy-app09 yaml]# cat nginx-pod.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: pc-replicaset
namespace: dev
spec:
replicas: 3
selector:
matchLabels:
app: nginx-pod
template:
metadata:
labels:
app: nginx-pod
spec:
containers:
- name: nginx
image: nginx
In this , The configuration item that needs new understanding is spec The following options :
(1)replicas: Specify the number of copies , In fact, it is the current rs created pod The number of , The default is 1
(2)selector: Selectors , What it does is it establishes pod Controller and pod The relationship between , Adopted Label Selector Mechanism in pod Define... On the template label, Define a selector on the controller (selector), It can indicate what the current controller can manage pod 了
(3)template: Templates , Is the current controller creation pod Template used , It's actually what I explained earlier pod The definition of
1. expand shrink pod Number
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl get ReplicaSet -n dev
NAME DESIRED CURRENT READY AGE
pc-replicaset 3 3 3 27m
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl edit rs pc-replicaset -n dev
# edit rs Number of copies of , modify spec:replicas: 5 that will do . This quantity is modified according to your requirements
2. Mirror elevation
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl edit rs pc-replicaset -n dev
# Directly modify the image version
3. Delete RS
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl delete rs pc-replicaset -n dev
perhaps
[root@t3-tkhijbs-jcsszy-app09 yaml]# kubectl delete -f nginx-pod.yaml
3、 ... and 、deployment(deploy)
In order to better solve the problem of service orchestration ,kubernetes stay V1.2 Version start , Introduced Deployment controller . It is worth mentioning that , This kind of controller doesn't directly manage pod, It's through management ReplicaSet To introduce management Pod, namely :Deployment management ReplicaSet,ReplicaSet management Pod. therefore Deployment Than ReplicaSet More powerful .
Support ReplicaSet All functions of
Support the stop of Publishing 、 continue
Support rolling upgrade and rollback version
[root@t3-tkhijbs-jcsszy-app09 yaml]# cat nginx-pod.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: pc-deployment
namespace: dev
spec:
replicas: 3
selector:
matchLabels:
app: nginx-pod
template:
metadata:
labels:
app: nginx-pod
spec:
containers:
- name: nginx
image: nginx
[root@t3-tkhijbs-jcsszy-app09 yaml]# kubectl apply -f nginx-pod.yaml
deployment.apps/pc-deployment created
1.Pod Vessel expansion and contraction capacity
[root@t3-tkhijbs-jcsszy-app09 yaml]# kubectl get pod -n dev
NAME READY STATUS RESTARTS AGE
pc-deployment-7d4f548fb9-mlksf 1/1 Running 0 94s
pc-deployment-7d4f548fb9-w5p2l 1/1 Running 0 94s
pc-deployment-7d4f548fb9-xlvvv 1/1 Running 0 94s
[root@t3-tkhijbs-jcsszy-app09 yaml]# kubectl edit deploy pc-deployment -n dev
# Just change the number here
replicas: 5
[root@t3-tkhijbs-jcsszy-app09 yaml]# kubectl get pod -n dev
NAME READY STATUS RESTARTS AGE
pc-deployment-7d4f548fb9-5z7n8 1/1 Running 0 27s
pc-deployment-7d4f548fb9-gfg7p 1/1 Running 0 27s
pc-deployment-7d4f548fb9-mlksf 1/1 Running 0 3m43s
pc-deployment-7d4f548fb9-w5p2l 1/1 Running 0 3m43s
pc-deployment-7d4f548fb9-xlvvv 1/1 Running 0 3m43s
2. Version rollback
2.1 --record
This parameter will record the update process
[root@t3-tkhijbs-jcsszy-app09 yaml]# cat nginx-pod.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: pc-deployment
namespace: dev
spec:
replicas: 3
selector:
matchLabels:
app: nginx-pod
template:
metadata:
labels:
app: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.17.1
[root@t3-tkhijbs-jcsszy-app09 yaml]# kubectl apply -f nginx-pod.yaml --record
deployment.apps/pc-deployment created
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl get rs -n dev
NAME DESIRED CURRENT READY AGE
pc-deployment-858db84f89 3 3 3 9s
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl get pod -n dev -w
NAME READY STATUS RESTARTS AGE
pc-deployment-858db84f89-8r5kg 1/1 Running 0 20s
pc-deployment-858db84f89-lc7wb 1/1 Running 0 20s
pc-deployment-858db84f89-s4f8f 1/1 Running 0 20s
Start updating mirror
kubectl set image deployment pc-deployment nginx=nginx:1.17.2 -n dev
After the update, I found , A new rs controller pc-deployment-6c78d7875b
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl get rs -n dev
NAME DESIRED CURRENT READY AGE
pc-deployment-6c78d7875b 3 3 3 85s
pc-deployment-858db84f89 0 0 0 4m14s
new pod Is based on pc-deployment-6c78d7875b Produced
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl get pod -n dev
NAME READY STATUS RESTARTS AGE
pc-deployment-6c78d7875b-9j27t 1/1 Running 0 3m1s
pc-deployment-6c78d7875b-c4wfl 1/1 Running 0 3m
pc-deployment-6c78d7875b-k5jsc 1/1 Running 0 2m57s
2.2 rollout
kubectl rollout: Version upgrade related functions , The following options are supported :
status Displays the current upgrade status
history Show Upgrade history
pause Pause the version upgrade process
resume Continue the suspended version upgrade process
restart Restart the version upgrade process
undo Roll back to the previous version ( have access to –to-revision Rollback to specified version )
example :
[root@t3-tkhijbs-jcsszy-app09 yaml]# cat nginx-pod.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: pc-deployment
namespace: dev
spec:
replicas: 3
selector:
matchLabels:
app: nginx-pod
template:
metadata:
labels:
app: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.17.1
[root@t3-tkhijbs-jcsszy-app09 yaml]# kubectl apply -f nginx-pod.yaml --record
deployment.apps/pc-deployment created
[root@t3-tkhijbs-jcsszy-app09 yaml]# kubectl get rs -n dev
NAME DESIRED CURRENT READY AGE
pc-deployment-858db84f89 3 3 3 23s
[root@t3-tkhijbs-jcsszy-app09 yaml]# kubectl get pod -n dev
NAME READY STATUS RESTARTS AGE
pc-deployment-858db84f89-khkml 1/1 Running 0 29s
pc-deployment-858db84f89-swkkv 1/1 Running 0 29s
pc-deployment-858db84f89-tnn8z 1/1 Running 0 29s
Change the mirror version
[root@t3-tkhijbs-jcsszy-app09 yaml]# vim nginx-pod.yaml
image: nginx:1.17.2
Update configuration
[root@t3-tkhijbs-jcsszy-app09 yaml]# kubectl apply -f nginx-pod.yaml --record
deployment.apps/pc-deployment configured
View update history
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl rollout history deploy pc-deployment -n dev
deployment.apps/pc-deployment
REVISION CHANGE-CAUSE
1 kubectl apply --filename=nginx-pod.yaml --record=true
2 kubectl apply --filename=nginx-pod.yaml --record=true
rs The controller has also been updated
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl get rs -n dev
NAME DESIRED CURRENT READY AGE
pc-deployment-6c78d7875b 3 3 3 19m
pc-deployment-858db84f89 0 0 0 33m
Start rolling back to the previous version
I'm going to use it directly here –to-revision=1 Rolled back to 1 edition , If you omit this option , Is to go back to the previous version
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl rollout undo deployment pc-deployment --to-revision=1 -n dev
deployment.apps/pc-deployment rolled back
[root@t3-tkhijbs-jcsszy-app09 ~]# kubectl get rs -n dev
NAME DESIRED CURRENT READY AGE
pc-deployment-6c78d7875b 0 0 0 21m
pc-deployment-858db84f89 3 3 3 34m
版权声明
本文为[smile_ pbb]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210611532076.html
边栏推荐
- CAN过滤器
- 3、 2 [Verilog HDL] hierarchical modeling of basic knowledge
- If I use Monet's color matching in scientific research pictures?
- ESP32 (UART 接收发送)-串口之接收发送通讯(4)
- Fundamentals of digital electronic technology 3.4 other types of MOS integrated circuits
- ESP32 LVGL8.1 ——event 事件 (event 17)
- vee-validate 验证
- Fundamentals of digital electronic technology 3.3 CMOS gate circuit (Part I)
- Pygame 坦克大战
- JDBC简单实现学生管理系统
猜你喜欢

Draw QQ charts with different distribution

How does excel form become latex format?

ESP32 LVGL8.1 ——slider 滑动条 (slider 22)

Draw biaxial separation diagram with ggplot2

【STM32】H743的25MHZ外部晶振下480MHz时钟的CubeMX配置图

idea如何打包成war包

R | create LEGO mosaic

imx6调试Lvds屏幕技术笔记

ESP32 LVGL8.1 ——Label 标签 (Style 14)

Making books with bookdown
随机推荐
How does excel form become latex format?
stm32mp157 wm8960音频驱动调试笔记
R | create LEGO mosaic
MySQL数据库备份命令--mysqldump
Realization of character relationship visualization and question answering system in a dream of Red Mansions based on Knowledge Map
2、 2 [FPGA] development environment construction
MNIST數據轉化為numpy數組格式的詳細步驟與講解
ESP32 LVGL8.1 ——arc 圆弧 (arc 19)
ESP32 LVGL8.1 ——Calendar 日历 (Calendar 25)
One article will take you to understand the double linked list
CANopen开启PDO定时发送后心跳帧时间错误,PDO迟迟不发送,CANopen时间轴错乱
Multi file upload (form submission)
Qt 信号与槽connect()的连接方式和emit 返回值
win10 系统重装后,如何恢复mysql 数据库(mysql-8.0.26-winx64.zip)
每日网安认证测试题(2022年4月15日)
3.bat中date命令问题
Using numpy library to realize convolution network from scratch and complete the recognition of MNIST handwritten data set
3、 1 [Verilog HDL] basic syntax quick start (FPGA Development)
每日CISSP认证常错题(2022年4月11日)
Tensorflow案例4:Mnist手写数字识别(线性神经网络)及其局限性