当前位置:网站首页>Go deep into RC, RS, daemonset and statefulset (VII)
Go deep into RC, RS, daemonset and statefulset (VII)
2022-06-29 09:29:00 【Lanson】
thorough RC、RS、DaemonSet、StatefulSet
One 、RC、RS
RC (ReplicationController ) The main function is to ensure that the number of copies of the container application is always kept at the user-defined number of copies . That is, if a container exits abnormally , Will automatically create a new Pod To replace ; And if the extra containers are recovered automatically
Kubernetes Official recommended use RS(ReplicaSet ) replace RC (ReplicationController ) Deployment ,RS Follow RC There is no essential difference , It's just that the names are different , also RS Support for aggregate selector
RC controller
apiVersion: v1
kind: ReplicationController
metadata:
name: frontend
spec:
replicas: 3
selector:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: php-redis
image: lansonlinux/myapp:v1
env:
- name: GET_HOSTS_FROM
value: dns
name: zhangsan
value: "123"
ports:
- containerPort: 80
RS controller
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
spec:
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: myapp
image: lansonlinux/myapp:v1
env:
- name: GET_HOSTS_FROM
value: dns
ports:
- containerPort: 80
Two 、DaemonSet
DaemonSet The controller ensures that all ( Or part of it ) All nodes run a specified Pod copy .
Whenever a node is added to the cluster , designated Pod A copy will also be added to the node
When a node is removed from the cluster ,Pod It's recycled
Delete one DaemonSet You can clean up all the created Pod
DaemonSet The typical usage scenarios are :
Run the cluster's storage daemon on each node , for example glusterd、ceph
Run the log collection daemons on each node , for example fluentd、logstash
Run monitoring daemons on each node , for example Prometheus Node Exporter、Sysdig Agent、collectd、Dynatrace OneAgent、APPDynamics Agent、Datadog agent、New Relic agent、Ganglia gmond、Instana Agent etc.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: logging
labels:
app: logging
spec:
selector:
matchLabels:
name: logging
template:
metadata:
labels:
name: logging
spec:
containers:
- name: logging
image: nginx
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
tolerations: # Set tolerance master The stain of
- key: node-role.kubernetes.io/master
effect: NoSchedule
See the effect
kubectl get pod -l name=logging -o wide
3、 ... and 、StatefulSet
Stateful replica set ;Deployment Such as stateless application deployment (stateless)
StatefulSet Use scenarios ; For applications with the following requirements ,StatefulSet just the thing :
Stable 、 The only Internet logo (dnsname)
StatefulSet Through its associated headless service for each pod Provide DNS Parse entry . If there is no head service DNS The entry is : " (namespace).svc.cluster.local", that pod The parsing entry is " (service name).$(namespace).svc.cluster.local", Every pod name It's the only one .
The stability of the 、 Persistent storage ;【 Every Pod Always correspond to their respective storage paths (PersistantVolumeClaimTemplate)】
Orderly 、 Elegant deployment and scaling .【 Add copies in order 、 Reduce copies , And perform cleanup when reducing copies 】
Orderly 、 Automatic rollover update .【 Rolling updates are performed automatically in sequence 】
Limit
Given Pod Must be stored by PersistentVolume The driver is based on the requested
storage classTo provide , Or by the administrator in advance .Delete or shrink StatefulSet and _ Can't _ Delete its associated storage volume . This is to ensure data security , It's usually better than automatically clearing StatefulSet All the related resources are more valuable .
StatefulSet Currently, headless services are needed to be responsible for Pod Network identity of . You need to be responsible for creating this service .
When the delete StatefulSets when ,StatefulSet No termination is provided Pod Guarantee . In order to achieve StatefulSet Medium Pod Can be terminated in an orderly and dignified manner , You can delete StatefulSet Zoom in to 0.
By default Pod Management strategy (
OrderedReady) When using Scroll to update , It is possible to enter a damaged state that requires human intervention to repair .
If an application does not need a stable network identity , Or you don't need to deploy in order 、 Delete 、 Add a copy of the , We should consider using Deployment This kind of Statelessness (stateless) The controller
apiVersion: v1 kind: Service # Define a load balancing network metadata: name: stateful-tomcat labels: app: stateful-tomcat spec: ports:
port: 8123 name: web targetPort: 8080 clusterIP: None #NodePort: Any machine +NodePort All have access to ,ClusterIP: This can be used in the cluster ip、service Domain name can access ,clusterIP: None; Do not assign clusters ip.headless; The headless service . Stable domain name selector: app: stateful-tomcat apiVersion: apps/v1 kind: StatefulSet # controller . metadata: name: stateful-tomcat spec: selector: matchLabels: app: stateful-tomcat # has to match .spec.template.metadata.labels serviceName: "stateful-tomcat" # Pay attention here , There must be a service The name is this replicas: 3 # by default is 1 template: metadata: labels: app: stateful-tomcat # has to match .spec.selector.matchLabels spec: terminationGracePeriodSeconds: 10 containers: - name: tomcat image: tomcat:7 ports: - containerPort: 8080 name: web # Observe the effect . Delete one , Name after restart ,ip It's all the same . Ensure the State
# details kubectl explain StatefulSet.spec podManagementPolicy: OrderedReady( In order )、Parallel( Concurrent )
serviceName -required- Set the service name , You can use the domain name to access pod 了 . pod-specific-string.serviceName.default.svc.cluster.local
# test kubectl run -i --tty --image busybox dns-test --restart=Never --rm /bin/sh ping stateful-tomcat-0.stateful-tomcat # We do not add storage volumes here . If any kubectl get pvc -l app=stateful-tomcat We can see that even if Pod Delete it and then pull it up , The volume is the same .
边栏推荐
猜你喜欢

Universal target detection based on region attention

Western Polytechnic University, one of the "seven national defense schools", was attacked by overseas networks

Wechat applet custom multi selector

Debug H5 page -vconsole

Mongodb persistence

Solutions to ineffective uniapp import components

Handwriting Redux thunk

UE4 在4.20-23版本安裝Datasmith插件

Wechat applet user refuses to authorize geographic location information and calls up the authorization window again

3DMax 卡死、白屏、渲染死机问题总结
随机推荐
Simple use of promise method
Abstract classes and interfaces
Mysql database and table splitting strategy and application scenarios
Mac mysql数据库基本操作
The principle of session and cookie
UE4 插件报错 Cannot open include file: ‘ModuleManager.h‘解决
Yotact real-time instance segmentation
微信小程序底部导航栏中间突出
《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(五)
Print service IP setting scheme
微信小程序项目:tab导航栏
MH/T 6040航空材料烟密度试验
Wechat applet custom multi selector
超融合架构和传统架构有什么区别?
pytorch总结—自动求梯度
LC236. 二叉树的最近公共祖先
Pytorch summary learning series - data manipulation
Keras to tf Vgg19 input in keras_ shape
Open3d hidden point removal
Difference between factory mode and strategy mode