当前位置:网站首页>Introduction to kubernetes resource objects and common commands (II)
Introduction to kubernetes resource objects and common commands (II)
2022-07-01 02:37:00 【Jiangxiaonan】
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/
边栏推荐
- 鼠标悬停效果八
- Cluster method synchronous execution framework suona
- The image variables in the Halcon variable window are not displayed, and it is useless to restart the software and the computer
- Applet custom top navigation bar, uni app wechat applet custom top navigation bar
- 旷世轻量化网络ShuffulNetV2学习笔记
- Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip
- Youmeng (a good helper for real-time monitoring of software exceptions: crash) access tutorial (the easiest tutorial for Xiaobai with some foundation)
- Ernie gram, an explicit and complete n-gram mask language model, implements explicit n-gram semantic unit knowledge modeling.
- SWT / anr problem - anr/je causes SWT
- Image preloading in JS
猜你喜欢
Restcloud ETl数据通过时间戳实现增量数据同步
详解数据治理知识体系
Leetcode interview question 17.10 Main elements
Contrastive learning of Class-agnostic Activation Map for Weakly Supervised Object Localization and
kubernetes资源对象介绍及常用命令(二)
如何在智汀中實現智能鎖與燈、智能窗簾電機場景聯動?
A preliminary understanding of operator overloading
Record a service deployment failure troubleshooting
What is project management?
Optimal transport Series 1
随机推荐
鼠标悬停效果一
import tensorflow.contrib.slim as slim报错
Sampling Area Lights
[PR # 5 A] two way running (state pressure DP)
How to add a condition for an associated table in an SQL statement [null value required or not required]
go: finding module for package
我想知道股票开户怎么开户?究竟网上开户是否安全么?
Pulsar Geo Replication/灾备/地域复制
How to buy Hong Kong shares in China? What platform is safer?
【微信小程序开发】样式汇总
RestCloud ETL实践之无标识位实现增量数据同步
[wechat applet development] style summary
Map array function
In the industrial Internet, "small" programs have "big" effects
Pytorch —— 基础指北_贰 高中生都能看懂的[反向传播和梯度下降]
Xception学习笔记
SWT / anr problem - binder stuck
园区运营效率提升,小程序容器技术加速应用平台化管理
Pytorch - - Basic Reference North Deux élèves du secondaire peuvent comprendre [Rétropropagation et Gradient descendant]
DenseNet网络论文学习笔记