当前位置:网站首页>[cloud native | kubernetes] in depth understanding of deployment (VIII)
[cloud native | kubernetes] in depth understanding of deployment (VIII)
2022-06-12 12:56:00 【Lanson】
List of articles
Deepen understanding Deployment
3、 ... and 、Deployment Renewal mechanism
1、 Scaling (Proportional Scaling)
2、HPA( Dynamic expansion and contraction )
4、Deployment Status and troubleshooting
Deepen understanding Deployment
One 、 What is? Deployment
- One Deployment by Pods and ReplicaSets Provide declarative update capabilities .
- You are responsible for describing Deployment Medium Target state , and Deployment controller (Controller) Change at a controlled rate The actual state , Turn it into Expected state ; Control cycle . for(){ xxx controller.spec()}
- Don't manage Deployment Owned ReplicaSet
- When we deploy an application, we usually don't write directly Pod, Instead, deploy a Deployment
- Deploy Preparation of the statute Deployments | Kubernetes
Two 、Deployment establish
- The basic format
.metadata.nameAppoint deploy namereplicasSpecify the number of copiesselectorSpecify the matching Pod Templates .templateMake a statement Pod Templates
Write a Deployment Of yaml give Pod Self healing and failover capabilities
- Check the... In the cluster Deployment when , The fields displayed are :
NAMELists the Deployment The name of .READYShows the available copy Count . The mode of display is “ The number of ready / Expected number ”.UP-TO-DATEShows the number of copies that have been updated to achieve the desired state .AVAILABLEShows the number of copies of the app available to users .AGEShows when the application is running .
- ReplicaSet The output contains the following fields :
NAMEList... In the namespace ReplicaSet The name of ;DESIREDShows the expected number of copies of the app , Creating Deployment The value defined when . This is the expected state ;CURRENTDisplays the number of copies in the current running state ;READYShows how many copies of the app can serve users ;AGEShows how long the app has been running .- Be careful :ReplicaSet The name of is always formatted as
[Deployment name ]-[ Random string ]. Where the random string is used pod-template-hash Randomly generated as seeds .
One Deploy Produce three
- Deployment resources
- replicaset resources
- Pod resources
Deployment control RS,RS control Pod Number of copies ReplicaSet: It only provides the control function of the number of copies Deployment: Every time a new version is deployed, a new replica set is created , Use him to record status , Rollback is also specified directly rs take effect
3、 ... and 、Deployment Renewal mechanism
- Only when the Deployment Pod Templates ( namely
.spec.template) When there is a change , for example The label or container image of the template is updated , Will trigger Deployment go online . Other updates ( If yes Deployment Perform the expansion and reduction operation ) It doesn't trigger an online action . - Online action principle : Create a new rs, When ready , Replace old rs( Will not be deleted at this time , because
revisionHistoryLimitSpecifies how many versions to keep ) - frequently-used kubectl command
################ to update #################################
#kubectl set image deployment Resource name Container name = Mirror name
kubectl set image deployment.apps/nginx-deployment php-redis=tomcat:8 --record
## yaml Extract all the key fields that can be updated hash.
web---- /hello
postman aservice- /hello
# Or modify the definition directly
kubectl edit deployment.v1.apps/nginx-deployment
# Check the status
kubectl rollout status deployment.v1.apps/nginx-deployment
################ View the history and roll back ####################################
# Check out the update history - See if the total number of history records we set is effective
kubectl rollout history deployment.v1.apps/nginx-deployment
# Roll back
kubectl rollout undo deployment.v1.apps/nginx-deployment --to-revision=2
############### Cumulative update ##############
# Pause recording version
kubectl rollout pause deployment.v1.apps/nginx-deployment
# Multiple update operations .
## For example, the resource limit has been updated
kubectl set resources deployment.v1.apps/nginx-deployment -c=nginx --limits=cpu=200m,memory=512Mi
## For example, the image version has been updated
kubectl set image deployment.apps/nginx-deployment php-redis=tomcat:8
## Continue operation several times
## See if the historical version records any changes
kubectl rollout history deployment.v1.apps/nginx-deployment
# Make multiple cumulative effects
kubectl rollout resume deployment.v1.apps/nginx-deployment1、 Scaling (Proportional Scaling)
maxSurge( Maximum increment ): How many instances should be added besides the current number .
maxUnavailable( Maximum unusable amount ): Number of unavailable instances during rolling update .
2、HPA( Dynamic expansion and contraction )
Concept :Pod Horizontal automatic expansion and contraction | Kubernetes
actual combat :HorizontalPodAutoscaler rehearse | Kubernetes
2.1、 You need to install metrics-server
2.2、 Installation steps
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: metrics-server
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
k8s-app: metrics-server
rbac.authorization.k8s.io/aggregate-to-admin: "true"
rbac.authorization.k8s.io/aggregate-to-edit: "true"
rbac.authorization.k8s.io/aggregate-to-view: "true"
name: system:aggregated-metrics-reader
rules:
- apiGroups:
- metrics.k8s.io
resources:
- pods
- nodes
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
k8s-app: metrics-server
name: system:metrics-server
rules:
- apiGroups:
- ""
resources:
- pods
- nodes
- nodes/stats
- namespaces
- configmaps
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
k8s-app: metrics-server
name: metrics-server-auth-reader
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
k8s-app: metrics-server
name: metrics-server:system:auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
k8s-app: metrics-server
name: system:metrics-server
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:metrics-server
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: v1
kind: Service
metadata:
labels:
k8s-app: metrics-server
name: metrics-server
namespace: kube-system
spec:
ports:
- name: https
port: 443
protocol: TCP
targetPort: https
selector:
k8s-app: metrics-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: metrics-server
name: metrics-server
namespace: kube-system
spec:
selector:
matchLabels:
k8s-app: metrics-server
strategy:
rollingUpdate:
maxUnavailable: 0
template:
metadata:
labels:
k8s-app: metrics-server
spec:
containers:
- args:
- --cert-dir=/tmp
- --kubelet-insecure-tls
- --secure-port=4443
- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
- --kubelet-use-node-status-port
image: registry.cn-hangzhou.aliyuncs.com/lanson_k8s_images/metrics-server:v0.4.3
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /livez
port: https
scheme: HTTPS
periodSeconds: 10
name: metrics-server
ports:
- containerPort: 4443
name: https
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /readyz
port: https
scheme: HTTPS
periodSeconds: 10
securityContext:
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
volumeMounts:
- mountPath: /tmp
name: tmp-dir
nodeSelector:
kubernetes.io/os: linux
priorityClassName: system-cluster-critical
serviceAccountName: metrics-server
volumes:
- emptyDir: {}
name: tmp-dir
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
labels:
k8s-app: metrics-server
name: v1beta1.metrics.k8s.io
spec:
group: metrics.k8s.io
groupPriorityMinimum: 100
insecureSkipTLSVerify: true
service:
name: metrics-server
namespace: kube-system
version: v1beta1
versionPriority: 100- kubectl apply that will do
- All runnning use
- kubectl top nodes --use-protocol-buffers
- kubectl top pods --use-protocol-buffers
2.3、 To configure hpa test
### The test image registry.cn-hangzhou.aliyuncs.com/lanson_k8s_images/php-hpa:latest
## Applied yaml Have done well
apiVersion: v1
kind: Service
metadata:
name: php-apache
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: php-apache
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: php-apache
name: php-apache
spec:
replicas: 1
selector:
matchLabels:
run: php-apache
template:
metadata:
creationTimestamp: null
labels:
run: php-apache
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/lanson_k8s_images/php-hpa:latest
name: php-apache
ports:
- containerPort: 80
resources:
requests:
cpu: 200m
##hpa To configure hpa.yaml
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: php-apache
spec:
maxReplicas: 10
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: php-apache
targetCPUUtilizationPercentage: 50
#3、 Stress test
kubectl run -i --tty load-generator --image=busybox /bin/sh
# Enter and hit the following command
kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"3、Canary( Canary deployment )
3.1、 Blue and green deployment VS Canary deployment
Blue and green deployment
Canary deployment
3.2、 A simple test of Canary
Use this image to test registry.cn-hangzhou.aliyuncs.com/lanson_k8s_images/nginx-test This mirror image docker run When -e msg=aaaa, Visit this nginx Page is to see aaaa
Step principle
- Prepare one Service, Load balancing Pod
- Prepare version v1 Of deploy, Prepare version v2 Of deploy
4、Deployment Status and troubleshooting
- Blog home page :https://lansonli.blog.csdn.net
- Welcome to thumb up Collection Leaving a message. Please correct any mistakes !
- This paper is written by Lansonli original , First appeared in CSDN Blog
- When you stop to rest, don't forget that others are still running , I hope you will seize the time to learn , Go all out for a better life
边栏推荐
- 【vim】vim插件YouCompleteMe配置文件
- 【数据库】navicat --oracle数据库创建
- C语言【23道】经典面试题【下】
- 机器人雅可比求解
- 大一女生废话编程爆火!懂不懂编程的看完都拴Q了
- Structure matérielle du système embarqué - introduction du Conseil de développement embarqué basé sur arm
- itk neighbhood
- 提升管道效率:你需要知道如何识别CI/CD管道中的主要障碍
- 下一个职场演讲PPT的明星,会不会是此刻的你【完美总结】
- Buu question brushing record - 4
猜你喜欢

数组——双指针技巧秒杀七道数组题目

The 4th Zhejiang CTF preliminary contest web pppop

Getting to know blob objects

Overview of embedded system 1- definition, characteristics and development history of embedded system

Pytorch官方Faster R-CNN源代码解析(一)——特征提取

Uniapp wechat applet long press the identification QR code to jump to applet and personal wechat

Binary tree (program)

什么时候运用二分搜索

leetcode 47. Permutations II 全排列 II(中等)

Known as the next generation monitoring system! See how awesome it is
随机推荐
STM32F1与STM32CubeIDE编程实例-设备驱动-DHT11温度温度传感器驱动
[EDA] chip layout design: VLSI layout design using electric
机械臂雅可比矩阵IK
Typescript and abstract classes
Newton method for solving roots of polynomials
A "murder case" caused by ES setting operation
VGA显示彩条和图片(FPGA)
unittest框架
Part of the fourth Zhejiang CTF finals
Openmax (OMX) framework
下一个职场演讲PPT的明星,会不会是此刻的你【完美总结】
Constant time delete / find any element in array
Array -- fancy traversal technique of two-dimensional array
常数时间删除/查找数组中的任意元素
配准后图像对比函数itk::CheckerBoardImageFilter
[database] Navicat -- Oracle database creation
Source of routing information
检测vector是否有交集
When to use binary search
机器人雅可比求解