当前位置: 首页 > news >正文

k8s入门-3

部署扩缩容kubectl get deployC:\Users\zhangkubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE hello-k8s-deployment 3/3 3 3 5h56m通过上面的命令我们先找到一个deploy用来进行测试。现在看他是3个副本现在我们把他先缩到1个。kubectl scale deploy hello-k8s-deployment --replicas1C:\Users\zhangkubectl scale deploy hello-k8s-deployment --replicas1 deployment.apps/hello-k8s-deployment scaled C:\Users\zhangkubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE hello-k8s-deployment 1/1 1 1 5h58m然后再加到5个。kubectl scale deploy hello-k8s-deployment --replicas5C:\Users\zhangkubectl scale deploy hello-k8s-deployment --replicas5 deployment.apps/hello-k8s-deployment scaled C:\Users\zhangkubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE hello-k8s-deployment 1/5 5 1 6h17m C:\Users\zhangkubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE hello-k8s-deployment 5/5 5 5 6h18m通过命令可以看出来它不是马上就建好5个的而是有一定的时间逐渐建立起来的。滚动更新建一个新版本docker build -t hello-k8s:1.0 .D:\LEO\project\test3\k8s-testdocker build -t hello-k8s:1.0 . [] Building 0.3s (10/10) FINISHED docker:desktop-linux [internal] load build definition from Dockerfile 0.0s transferring dockerfile: 204B 0.0s [internal] load metadata for docker.io/library/python:3.10-slim 0.1s [internal] load .dockerignore 0.0s transferring context: 2B 0.0s [1/5] FROM docker.io/library/python:3.10-slimsha256:70f65c721aaddfb22b20ed6ec12606c59d9592493c5fcb6639f3d0e8 0.0s resolve docker.io/library/python:3.10-slimsha256:70f65c721aaddfb22b20ed6ec12606c59d9592493c5fcb6639f3d0e8 0.0s [internal] load build context 0.0s transferring context: 63B 0.0s CACHED [2/5] WORKDIR /app 0.0s CACHED [3/5] COPY requirements.txt . 0.0s CACHED [4/5] RUN pip install --no-cache-dir -r requirements.txt 0.0s CACHED [5/5] COPY app.py . 0.0s exporting to image 0.1s exporting layers 0.0s exporting manifest sha256:14484ee5ad887573cfd12ac62cbf7eb5547ff03226021a1c4234d5e12b02f89b 0.0s exporting config sha256:d69d28bf3d152a2e5b862be56583bac59c13ab81873688aa94be4c2403458c43 0.0s exporting attestation manifest sha256:693e5b58682b01e416285b2a47593679eee55578474b79d3e8a6866ea7158774 0.0s exporting manifest list sha256:f989154c957c2aaba2e37f7abf7ca172b0a54e53f6532dd7ed10ea4d5ac9d43d 0.0s naming to docker.io/library/hello-k8s:1.0 0.0s unpacking to docker.io/library/hello-k8s:1.0 0.0s更换版本D:\LEO\project\test3\k8s-testkubectl set image deploy hello-k8s-deployment hello-k8shello-k8s:1.0deployment.apps/hello-k8s-deployment image updatedD:\LEO\project\test3\k8s-testkubectl rollout status deploy hello-k8s-deploymentdeployment hello-k8s-deployment successfully rolled out查看更换版本的情况可以用下面的方式来确认D:\LEO\project\test3\k8s-testkubectl rollout history deploy hello-k8s-deployment deployment.apps/hello-k8s-deployment REVISION CHANGE-CAUSE 1 none 2 none D:\LEO\project\test3\k8s-testkubectl rollout history deploy hello-k8s-deployment --revision2 deployment.apps/hello-k8s-deployment with revision #2 Pod Template: Labels: apphello-k8s pod-template-hash5dbcc46558 Containers: hello-k8s: Image: hello-k8s:1.0 Port: 5000/TCP Host Port: 0/TCP Liveness: http-get http://:5000/health delay5s timeout1s period10s #success1 #failure3 Readiness: http-get http://:5000/health delay5s timeout1s period5s #success1 #failure3 Environment: none Mounts: none Volumes: none Node-Selectors: none Tolerations: none D:\LEO\project\test3\k8s-testkubectl rollout history deploy hello-k8s-deployment --revision1 deployment.apps/hello-k8s-deployment with revision #1 Pod Template: Labels: apphello-k8s pod-template-hash54d8cb895d Containers: hello-k8s: Image: hello-k8s:latest Port: 5000/TCP Host Port: 0/TCP Liveness: http-get http://:5000/health delay5s timeout1s period10s #success1 #failure3 Readiness: http-get http://:5000/health delay5s timeout1s period5s #success1 #failure3 Environment: none Mounts: none Volumes: none Node-Selectors: none Tolerations: none最后一步咱们再试一下回退。kubectl rollout undo deploy hello-k8s-deploymentD:\LEO\project\test3\k8s-testkubectl rollout history deploy hello-k8s-deployment deployment.apps/hello-k8s-deployment REVISION CHANGE-CAUSE 1 none 2 none D:\LEO\project\test3\k8s-testkubectl rollout undo deploy hello-k8s-deployment deployment.apps/hello-k8s-deployment rolled back D:\LEO\project\test3\k8s-testkubectl rollout history deploy hello-k8s-deployment deployment.apps/hello-k8s-deployment REVISION CHANGE-CAUSE 2 none 3 none验证成果还可以通过查看当前的配置文件来完成这个更好一点。kubectl get deploy hello-k8s-deployment -o yaml可以通过输出看到 image: hello-k8s:latest这就很明显了。说明已经回退到了之前的版本。完成。下次再研究一下分环境的功能。
http://www.zskr.cn/news/1407238.html

相关文章:

  • 学术写作提质新思路:paperxie 毕业论文 AI 创作功能实操使用解析
  • 如何快速掌握C++游戏开发:基于Cocos2d-x的植物大战僵尸完整实战指南
  • Cache主存地址映射实战:从课后题到三种映射方式的地址格式设计
  • MCP博客园工具集成测试v2
  • 2026年驱蚊雾森系统排名:最新权威排名与专业指南。 - 资讯快报
  • 建筑领域“混凝土配合比智能优化”高价值专利案例:一种钢纤维混凝土抗压强度预测方法
  • 别让“能用”的IP拖垮业务——共享IP易封禁的原因与IP风险等级评估实战
  • 2026年苏州名酒回收行业研究报告:专业检测机构发展现状与趋势 - 资讯纵览
  • 2026上海二奢回收商家综合实力测评|6大维度评测,权威推荐 - GrowthUME
  • 成都本地人都要去的宝藏火锅店推荐|口碑4.8分以上必吃榜单 - TOP10品牌推荐榜单
  • 【爬虫随笔】WX小程序强制开启F12开发者工具
  • 省钱又提效!大模型Token优化与减少使用技巧全指南
  • 算法复现成保研关键:新工科背景提升该看重代码还是文书?
  • 【有想法】系列之:用python把成本核算从需要数天缩到数分钟
  • 别再死记硬背!用一张图+Python代码搞定运筹学对偶问题的对称形式转换
  • 如何永久保存微信聊天记录:开源工具的完整解决方案
  • 网球手链品牌TOP5实测:戴过才知道这3款最值得入! - 资讯纵览
  • 强品牌,真赋能:嘉宝莉石艺漆两场渠道推广会圆满收官 - 资讯快报
  • 【ChatGPT财务预测模型实战指南】:零代码接入、3天上线、准确率提升47%的央企级落地方法论
  • 终极指南:5分钟掌握webMAN MOD,让你的PS3变身全能游戏中心
  • PyTorch乘法全解析
  • 搭上鸿蒙“快车”,ToDesk远控如何用全场景体验点燃效率革命?
  • Codex 桌面版 使用国内大模型系列一 | EchoBird
  • Ubuntu 24.04 下 NVIDIA GT 1030 显卡驱动故障修复全记录
  • ARM芯片JTAG通信故障分析与解决方案
  • 多评价器强化学习在四足机器人控制中的应用与优化
  • 财务预测模型升级迫在眉睫:ChatGPT已支持IFRS 9预期信用损失建模,仅剩72小时获取监管认可接口文档
  • 电力工程项目信息平台的数据价值:中项网如何提升设备企业获客效率 - GrowthUME
  • 2026年罗斯蒙特差压变送器国产平替:五家优选深度解析 - 科技焦点
  • 选变频器风机品牌怎么选?2026年5月推荐TOP5评测工业场景防过载专业选择指南