当前位置:网站首页>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
边栏推荐
- Unity2021-Scene视图中物体无法直接选中的解决办法
- 2022 electrician (intermediate) recurrent training question bank and answers
- Do securities account opening affect the security of account opening
- [microservice openfeign] feign's log record
- 【技能】创建.bat快速打开网页
- 浏览器本地存储
- [software] phantomjs screenshot
- AUTOSAR learning record (1) – ECUM_ Init
- redisson使用全解——redisson官方文档+注释(下篇)
- ctfshow-web351(SSRF)
猜你喜欢

base64

Eigen矩阵运算库快速上手

Eigen matrix operation Library

Félicitations pour l'inscription réussie de wuxinghe

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)

TodoList经典案例①
![C language implementation [minesweeping game] full version (implementation source code)](/img/70/60f9a61bd99fa5fb5fab679a32528e.png)
C language implementation [minesweeping game] full version (implementation source code)

【目标检测】目标检测界的扛把子YOLOv5(原理详解+修炼指南)

2022 test questions and mock examinations for main principals of hazardous chemicals business units

Apple账号密码自动填充
随机推荐
Browser local storage
下载Xshell和Xftp
Kdtree notes
The programmer of Beipiao posted a post for help late at night: I am lonely when my girlfriend is gone
长路漫漫、技术作伴
AUTOSAR learning record (1) – ECUM_ Init
手机开户选哪个证券公司比较好,哪个更安全
Discussion on several research hotspots of cvpr2022
【目标检测】目标检测界的扛把子YOLOv5(原理详解+修炼指南)
Custom events of components ①
【推荐系统】美团外卖推荐场景的深度位置交互网络DPIN的突破与畅想
Understanding of Turing test and Chinese Room
热烈祝贺五行和合酒成功挂牌
2022 test question bank and simulation test of tea master (primary) operation certificate
MATLAB之基础知识
Reply and explanation on issues related to "online training of network security education in 2022"
[lingo] solve quadratic programming
ctfshow-web351(SSRF)
[Shenzhen IO] precise Food Scale (some understanding of assembly language)
TodoList经典案例①