当前位置:网站首页>kubernetes资源对象介绍及常用命令(二)
kubernetes资源对象介绍及常用命令(二)
2022-07-01 07:24:00 【傻啦猫@[email protected]】
Deployment
Deployment顾名思义,就是部署的意思。Deploymen用于控制Pod,使Pod拥有多副本,自愈,扩缩容等能力。
多副本
副本,可以理解为Pod的数量。这些Pod会被随机分配到集群中的任意节点。
创建一次名叫my-app的部署,使用镜像为nginx。副本数为3。
命令行方式
kubectl create deploy my-app --image=nginx --replicas=3
yaml方式,my-app.yml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: my-app
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- image: nginx
name: nginx
kubectl apply -f my-app.yml

扩缩容
扩缩容是将原有的副本数进行扩大或缩小。流量大的时候可以扩容,流量高峰过后可以进行缩容,资源利用最大化。
命令行方式
kubectl scale --replicas=5 deployment/my-app
副本数由3个变成5个。
修改yaml方式
kubectl edit deployment my-app
将replicas修改成自己想要的数量,保存退出即可进行扩缩容。

自愈&故障转移
使用Deployment部署的应用始终和设定的副本数保持一致,当pod出现异常或者服务器宕机,亦或者删除pod,会在正常的节点重新拉起副本,以满足我们设定的副本数量。
我们模拟将k8s-worker1节点宕机。
发现k8s-worker1节点的两个pod状态为Terminating。在k8s-worker2多了两个Running状态的pod。实现了故障转移。
扩展:
查看集群内pod信息。
kubectl get pod -owide
监控集群内pod情况,打印详细信息。
kubectl get pod -w

阈值:pod出现了异常状况,k8s并不会立即杀死pod进行重启,而是超过了阈值才进行相应的重启操作,以防止因短暂网络问题等故障导致的频繁启动pod。
滚动更新
传统的更新升级需要将服务停止在做升级操作。k8s不用停止服务,会将pod依次替换成最新的,即启动一个新pod,杀死一个旧pod,直至全部更新完为止。
将nginx镜像更新为1.16.1版本。
命令行方式
kubectl set image deployment/my-app nginx=nginx:1.16.1 --record
修改yaml方式
kubectl edit deployment/my-app
将images修改为1.16.1中,保存退出即可。

扩展:
查看某次部署的yaml。
kubectl get deployment [my-app] -oyaml
版本回退
将版本回退到历史的某一次。
查看历史记录
[[email protected] ~]# kubectl rollout history deployment/my-app
deployment.apps/my-app
REVISION CHANGE-CAUSE
1 <none>
2 kubectl set image deployment/my-app nginx=nginx:1.16.1 --record=true
[[email protected] ~]#
查看某个历史详情
[[email protected] ~]# kubectl rollout history deployment/my-app --revision=2
deployment.apps/my-app with revision #2
Pod Template:
Labels: app=my-app
pod-template-hash=5ff664f457
Annotations: kubernetes.io/change-cause: kubectl set image deployment/my-app nginx=nginx:1.16.1 --record=true
Containers:
nginx:
Image: nginx:1.16.1
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
[[email protected] ~]#
回滚(回到上次)
[[email protected] ~]# kubectl rollout undo deployment/my-app
deployment.apps/my-app rolled back
[[email protected] ~]#
回滚(回到指定版本)
[[email protected] ~]# kubectl rollout undo deployment/my-app --to-revision=2
deployment.apps/my-app rolled back
[[email protected] ~]#
回滚的版本需要按照自己需要的填写。
小结:

除了Deployment,k8s还有 StatefulSet 、DaemonSet 、Job 等 类型资源。我们都称为 工作负载。 有状态应用使用 StatefulSet 部署,无状态应用使用 Deployment 部署 https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/
本文由 mdnice 多平台发布
版权声明
本文为[傻啦猫@[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45842494/article/details/125550761
边栏推荐
- 关于图灵测试和中文屋Chinese room的理解
- iNFTnews | 从《雪崩》到百度“希壤”,元宇宙30年的16件大事
- 运维管理系统,人性化操作体验
- [programming training] delete public characters (hash mapping) + team competition (greedy)
- Minecraft 1.16.5模组开发(五十一) 方块实体 (Tile Entity)
- JSP - 分页
- 2022危险化学品经营单位主要负责人试题及模拟考试
- 【编程强训2】排序子序列+倒置字符串
- Is the account opening of GF Securities safe and reliable? How to open GF Securities Account
- 盘点华为云GaussDB(for Redis)六大秒级能力
猜你喜欢

Ctfhub port scan (SSRF)
![[recommendation technology] matlab simulation of network information recommendation technology based on collaborative filtering](/img/fb/dc03f97f12488e53d706a05da9faea.png)
[recommendation technology] matlab simulation of network information recommendation technology based on collaborative filtering

We found a huge hole in MySQL: do not judge the number of rows affected by update!!!

Redisson utilise la solution complète - redisson Documents officiels + commentaires (Partie 1)

熱烈祝賀五行和合酒成功掛牌

ctfshow-web351(SSRF)

Autosar 学习记录(1) – EcuM_Init

Are there any practical skills for operation and maintenance management

Paging in servlets and JSPS

Challenges faced by operation and maintenance? Intelligent operation and maintenance management system to help you
随机推荐
JAX的深度学习和科学计算
Illusory and simple screen raindrop post-processing effect
Unity2021-Scene视图中物体无法直接选中的解决办法
Microsoft announces open source (Godel) language model chat robot
Stepsister becomes stepmother, son breaks off relationship with himself, and musk, the world's richest man, why is it so miserable?
Fix the problem that the AI video intelligent platform easycvr device video cannot be played
Reply and explanation on issues related to "online training of network security education in 2022"
Apple账号密码自动填充
组件的自定义事件①
Atguigu---- scaffold --02- use scaffold (2)
redisson使用全解——redisson官方文档+注释(下篇)
【编程强训2】排序子序列+倒置字符串
【R语言】年龄性别频数匹配 挑选样本 病例对照研究,对年龄性别进行频数匹配
微软宣布开源 (GODEL) 语言模型聊天机器人
Cadence OrCAD Capture “网络名”相同,但是未连接或连接错误的解放方案之nodename的用法
LeetCode+ 71 - 75
DC-4 target
Pourquoi tant de gens sont - ils devenus des gestionnaires de produits? Quelles sont les perspectives de développement des gestionnaires de produits?
1286_FreeRTOS的任务优先级设置实现分析
ctfhub-端口扫描(SSRF)