当前位置:网站首页>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建立成功.
边栏推荐
猜你喜欢
随机推荐
radiobutton的使用
QGIS 加载WMS数据,重新投影
Ubantu专题5:设置静态ip地址
Ubuntu Topic 5: Setting a Static IP Address
网银被盗?这篇文章告诉你如何安全使用网银
JVM参数解析 Xmx、Xms、Xmn、NewRatio、SurvivorRatio、PermSize、PrintGC「建议收藏」
使用 GraphiQL 可视化 GraphQL 架构
Linux check redis version (check mongodb version)
Synchronized and volatile interview brief summary
R language moves time series data forward or backward (custom lag or lead period): use the lag function in the dplyr package to move the time series data forward by one day (set the parameter n to a p
Internet banking stolen?This article tells you how to use online banking safely
Unity中实现点选RenderTexture中的3D模型
Jmeter常用的十大组件
Efficient use of RecyclerView Section 3
工程流体力学复习
svn安装及使用(身体功能手册)
Why don't you make a confession during the graduation season?
【MySQL】Mysql范式及外键作用
Web自动化实战——Selenium4(自动化测试环境的搭建)
Matlab matrix basic operations (definition, operation)









