当前位置:网站首页>Deployment application life cycle and Pod health check
Deployment application life cycle and Pod health check
2022-07-31 15:14:00 【GottdesKrieges】
通过DeploymentThe general process of the deployed application lifecycle is :
Deployment应用生命周期
部署
通过yaml文件部署项目:
kubectl apply -f web.yaml
Or command line ad hoc deployment(不推荐,一般只用于测试):
kubectl create deployment web --image=nginx:1.16 --replicas=3
升级
After an application is deployed, it usually undergoes a version upgrade.
#方法一:Upgrade via configuration file
kubectl apply -f xxx.yaml
#方法二:Directly upgrade the application image version
kubectl set image deployment/web nginx=nginx:1.17
#方法三:Modify the original deployment to useyaml文件
kubectl edit deployment/web
K8SUpgrade via rolling release.滚动发布Refers to upgrading only one or more services at a time,After the upgrade is complete, add them to the production environment one by one.不断执行这个过程,Until all the old versions in the cluster are upgraded to the new version.
Review the rolling upgrade process:
kubectl describe deployment xxx
kubectl rollout status deployment/xxx
K8S通过ReplicaSet控制器(RS)维护Pod的副本数量.RSContinue to compare the currentPodquantity and expectationsPod数量.Deployment每次发布都会创建一个RS作为记录,用于实现滚动升级和版本回退.
如果我们直接删除Deployment中的一个Pod,RS会生成一个新的Pod,to achieve the desiredPod数量.
kubectl delete pod xxx
kubectl get pods
查看RS记录:
kubectl get rs [-n default]
查看版本对应RS记录:
kubectl rollout history deployment xxx
回退
After an application upgrade fails,It is common to roll back the app version.
查看历史版本:
kubectl rollout history deployment/web
回退到上一个版本:
kubectl rollout undo deployment/web
回滚到指定历史版本:
kubectl rollout undo deployment/web --to-revision=2
Check the version number corresponding to the image:
kubectl describe rs | grep -E "revision|Image"
kubectl describe rs xxx | grep -E "revision|Image"
kubectl describe $(kubectl get rs -o name | grep "web1-") | grep -E "revision|Image"
扩容
as the volume of business changes,Usually, the application needs to be scaled horizontally(或者缩容).
方法一:修改yaml配置文件里的replicas值,再重新apply.
kubectl edit deployment/web
kubectl apply -f xxx.yaml
方法二:使用scaleThe command directly expands and shrinks.
kubectl scale deployment web --raplicas=10
下线
After the project is offline,Need to delete no longer usedDeployment和Service.
kubectl delete deploy/web
kubectl delete svc/web
或者
kubectl delete -f xxx.yaml
Pod健康检查
Pod是K8S创建和管理的最小单元,由一个或多个容器组成.Pod中的容器共享网络和存储资源.PodThe containers in are always in the same oneNode上,不会跨Node.
可以单独运行一个Pod:
kubectl apply -f pod.yaml
kubectl run nginx --image=nginx
此时的Pod不属于任何一个Deployment,也没有对应的ReplicaSet,So a new one will not be automatically generated after being deleted.
Sidecar模式
一个Pod中可以运行多个容器.通过在Pod中定义专门容器,来执行主业务容器需要的辅助工作,这种部署Pod的方法被称为边车模式(Sidecar).The benefit is the accessibility(如日志收集、应用监控)Same as the main business container解耦,实现独立发布和能力重用.
重启策略
可以为PodDefine a restart strategyrestartPolicy,Generally, the following three modes can be selected:
Always:当容器终止退出后,总是重启容器,为默认策略;OnFailure:当容器异常退出(退出状态码非0)时,才重启容器;Never:当容器终止退出时,从不重启容器.
健康检查
可以为PodDefine health checks,Generally, the following three inspection probes can be selected:
livenessProbe(存活检查):如果检查失败,将kill容器,并根据重启策略进行操作.readinessProbe(就绪检查):如果检查失败,会把Pod从Service endpoints中剔除.startupProbe(启动检查):The liveness check takes over after the startup check succeeds,Used to protect slow-start containers.
Health checks can generally be implemented in the following three ways:
httpGet:发送HTTP请求,返回200-400范围状态码为成功;exec:执行shell命令返回状态码是0为成功;tcpSocket:发起TCP Socket建立成功.
边栏推荐
- Destruction order of thread_local variables
- Codeforces Round #796 (Div. 2)(A-D)
- NC | 斯坦福申小涛等开发数据可重复分析计算框架TidyMass
- TRACE32——基于SNOOPer的变量记录
- Why don't you make a confession during the graduation season?
- Essential Learning for Getting Started with Unity Shader - Transparency Effect
- 力扣:714. 买卖股票的最佳时机含手续费
- Word表格转到Excel中
- Gorm—Go language database framework
- 【MySQL】Mysql范式及外键作用
猜你喜欢

Synchronized和volatile 面试简单汇总

Essential Learning for Getting Started with Unity Shader - Transparency Effect

01 Encounter typescript, build environment

QGIS 加载WMS数据,重新投影

四象限时间管理有多好用?

Synchronized and volatile interview brief summary

工程流体力学复习

TRACE32 - C source code association

使用 PyTorch 检测眼部疾病

【MySQL】Mysql范式及外键作用
随机推荐
763.划分字母区间——之打开新世界
R language test whether the sample conforms to normality (test whether the sample comes from a normally distributed population): shapiro.test function tests whether the sample conforms to the normal d
R语言检验样本是否符合正态性(检验样本是否来自一个正态分布总体):shapiro.test函数检验样本是否符合正态分布(normality test)
JVM参数解析 Xmx、Xms、Xmn、NewRatio、SurvivorRatio、PermSize、PrintGC「建议收藏」
Kubernetes原理剖析与实战应用手册,太全了
力扣:56. 合并区间
435. 无重叠区间
Word table to Excel
Linux查看redis版本(查看mongodb版本)
易驱线主控芯片对比(电动三轮电机90O瓦世纪通达)
Synchronized和volatile 面试简单汇总
NPM Taobao mirror (latest version) released a new version of npm mirror at 2021-11-21 16:53:52 [easy to understand]
leetcode303 Weekly Match Replay
Nuget package and upload tutorial
梅克尔工作室-第一次
自适应控制——仿真实验三 用超稳定性理论设计模型参考自适应系统
JVM parameter analysis Xmx, Xms, Xmn, NewRatio, SurvivorRatio, PermSize, PrintGC "recommended collection"
Ubantu专题5:设置静态ip地址
R语言ggplot2可视化:使用ggpubr包的ggmaplot函数可视化MA图(MA-plot)、font.legend参数和font.main参数设置标题和图例字体加粗
Emmet 语法