当前位置:网站首页>Introduction to kubernetes resource objects and common commands (II)
Introduction to kubernetes resource objects and common commands (II)
2022-07-01 07:31:00 【Silly [email protected]】
Deployment
Deployment seeing the name of a thing one thinks of its function , Deployment means deployment .Deploymen Used to control the Pod, send Pod Have multiple copies , self-healing , Ability to expand, shrink, etc .
Multiple copies
copy , It can be understood as Pod The number of . these Pod Will be randomly assigned to any node in the cluster .
Create a named my-app Deployment of , Use image as nginx. Replications for 3.
Command line mode
kubectl create deploy my-app --image=nginx --replicas=3
yaml The way ,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

Expansion and contraction capacity
Expanding or shrinking capacity is to expand or reduce the original number of copies . When the traffic is large, the capacity can be expanded , After the flow peak, the volume can be reduced , Maximize resource utilization .
Command line mode
kubectl scale --replicas=5 deployment/my-app
The number of copies is determined by 3 A into 5 individual .
modify yaml The way
kubectl edit deployment my-app
take replicas Change it to the quantity you want , Save and exit to expand or shrink the volume .

self-healing & Fail over
Use Deployment The deployed application is always consistent with the set number of copies , When pod Exceptions or server downtime occur , Or delete pod, The replica will be pulled up again on the normal node , To meet the number of copies we set .
We simulate the k8s-worker1 The node is down .
Find out k8s-worker1 Two of the nodes pod Status as Terminating. stay k8s-worker2 Two more Running State of pod. Failover is achieved .
Expand :
Look inside the cluster pod Information .
kubectl get pod -owide
Monitor the cluster pod situation , Print details .
kubectl get pod -w

threshold :pod An abnormal condition has occurred ,k8s Will not kill immediately pod To restart , Instead, the corresponding restart operation is performed only after the threshold is exceeded , To prevent frequent startup caused by faults such as short-term network problems pod.
Scroll to update
The traditional updating and upgrading requires that the service be stopped for upgrading .k8s Don't stop the service , Will pod Replace... In turn Become the latest , That is, start a new pod, Kill an old pod, Until all updates are completed .
take nginx Image update to 1.16.1 edition .
Command line mode
kubectl set image deployment/my-app nginx=nginx:1.16.1 --record
modify yaml The way
kubectl edit deployment/my-app
take images It is amended as follows 1.16.1 in , Save to exit .

Expand :
View a deployed yaml.
kubectl get deployment [my-app] -oyaml
Version rollback
Rollback the version to a certain time in history .
View history
[[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] ~]#
View a history detail
[[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] ~]#
Roll back ( Back to the last time )
[[email protected] ~]# kubectl rollout undo deployment/my-app
deployment.apps/my-app rolled back
[[email protected] ~]#
Roll back ( Back to the specified version )
[[email protected] ~]# kubectl rollout undo deployment/my-app --to-revision=2
deployment.apps/my-app rolled back
[[email protected] ~]#
The rollback version should be filled in as required .
Summary :

except Deployment,k8s also StatefulSet 、DaemonSet 、Job etc. Type resources . We all call it The workload . Stateful applications use StatefulSet Deploy , Stateless applications use Deployment Deploy https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/
This paper is written by mdnice Multi platform Publishing
版权声明
本文为[Silly [email protected][email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207010723585906.html
边栏推荐
- C语言实现【扫雷游戏】完整版(实现源码)
- TodoList经典案例①
- 【推荐系统】美团外卖推荐场景的深度位置交互网络DPIN的突破与畅想
- 奥迪AUDI EDI 项目中供应商需要了解哪些信息?
- 2022年茶艺师(中级)复训题库及答案
- 【Flutter 问题系列第 72 篇】在 Flutter 中使用 Camera 插件拍的图片被拉伸问题的解决方案
- Kdtree notes
- Minecraft 1.16.5 module development (51) tile entity
- I bet on performance and won the CTO of the company. I want to build Devops platform!
- LeetCode+ 71 - 75
猜你喜欢
随机推荐
【目标检测】目标检测界的扛把子YOLOv5(原理详解+修炼指南)
2022制冷与空调设备运行操作国家题库模拟考试平台操作
redisson使用全解——redisson官方文档+注释(中篇)
十大劵商如何开户?另外,手机开户安全么?
Custom events of components ①
How to create an exclusive vs Code theme
热烈祝贺五行和合酒成功挂牌
Eigen矩阵运算库快速上手
Redisson uses the full solution - redisson official document + comments (Part 2)
[软件] phantomjs屏幕截图
运维管理有什么实用的技巧吗
Warm congratulations on the successful listing of five elements hehe liquor
未来互联网人才还稀缺吗?哪些技术方向热门?
C language implementation [Sanzi chess game] (step analysis and implementation source code)
Discussion on several research hotspots of cvpr2022
Is the account opening of GF Securities safe and reliable? How to open GF Securities Account
ctfhub-端口扫描(SSRF)
组件的自定义事件①
2022 mobile crane driver test exercises and online simulation test
【微服务|openfeign】Feign的日志记录









