当前位置:网站首页>[cloud native | kubernetes] in depth understanding of deployment (VIII)
[cloud native | kubernetes] in depth understanding of deployment (VIII)
2022-06-30 12:15:00 【Lanson】
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 **
revisionHistoryLimit** Specifies 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-deployment
1、 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
边栏推荐
- beego开发博客系统学习(二)
- 杂文:自家的智能家居方案研究
- wallys/600VX – 2 × 2 MIMO 802.11ac Mini PCIe Wi-Fi Module, Dual Band, 2,4GHz / 5GHz QCA 9880
- Hannaiping of Qilin software: the construction of Digital China needs its own open source root community
- 并行接口8255A
- R language ggplot2 visualization: gganimate package is based on Transition_ The time function creates a dynamic scatter graph animation (GIF), and uses the labs function to add a dynamic time title to
- STM32 移植 RT-Thread 标准版的 FinSH 组件
- go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
- Joplin实现样式更改
- Time function and clock_ Differences between gettime() functions
猜你喜欢
随机推荐
A review of quantum neural networks 2022 for generating learning tasks
【BUG解决】fiftyone报AttributeError: module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipeline‘错误解决方法
海思3559 sample解析:venc
Joplin实现样式更改
1020. number of enclaves
zabbix监控TCP连接个数
品达通用权限系统(Day 7~Day 8)
1175. 质数排列 : 乘法原理运用题
用宝塔建第2个网站时网站总是报错:No input file specified.
R语言ggplot2可视化:gganimate包基于transition_time函数创建动态散点图动画(gif)、使用labs函数为动画图添加动态时间标题(抽取frame_time信息)
移除无效的括号[用数组模拟栈]
8253计数器介绍
智慧法院新征程,无纸化办公,护航智慧法院绿色庭审
解决服务器重装无法通过ssh连接的问题
R语言ggplot2可视化:使用ggplot2可视化散点图、使用scale_color_viridis_d函数指定数据点的配色方案
DMA controller 8237a
ModelAtrs声音检测,基于声学特征的异响检测
Object mapping - mapping Mapster
Edusoho enterprise training version intranet only deployment tutorial (to solve the problems of player, upload and background jam)
When building the second website with pagoda, the website always reports an error: no input file specified








