当前位置:网站首页>[cloud native | kubernetes] in depth understanding of pod (VI)
[cloud native | kubernetes] in depth understanding of pod (VI)
2022-06-28 08:33:00 【Lanson】
Deepen understanding Pod
One 、 What is? Pod

_Pod_ It's a group. ( One or more ) Containers (docker Containers ) Set ( Like in a pea pod ); These containers share storage 、 The Internet 、 And how to run these container declarations .
We don't usually create Pod, Instead, create some workloads for them to create Pod
Pod In the form of
Pod Self recovery capability for containers (Pod Automatic restart of failed containers )
Pod I can't recover myself ,Pod It's really gone when it's deleted (100,MySQL、Redis、Order) Or hope k8s The cluster can restart this itself elsewhere Pod
Single container Pod
Multi container collaboration Pod. We can call another container **
SideCar( Enabling applications )
**Pod Naturally, there are two kinds of shared resources for its member containers : Network and storage
One Pod By a Pause Containers Set up the whole Pod The network of all containers inside 、 Namespace and other information
systemctl status It can be observed that .Pod Relationship with container process
kubelet Start a Pod, Prepare two containers , One is Pod Declared application container (nginx), The other is Pause.Pause Set up all kinds of in cyberspace for the current application container .

Two 、Pod Use
You can write deploy And so on yaml file , Finally create pod, You can also create
Pod The template is as follows
# Here is Pod Template
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: hello
image: busybox
command: ['sh', '-c', 'echo "Hello, Kubernetes!" && sleep 3600']
restartPolicy: OnFailure
# The above is Pod Template
3、 ... and 、Pod Life cycle

Pod start-up , Will first successively Execute all initialization containers , There is a failure , be Pod Cannot start
Next Start all application containers ( Every application container must be able to run all the time ),Pod Start formal work , A startup failure will Try to restart Pod This container inside ,Pod As long as it is NotReady,Pod We will not provide external services
To write yaml Test life cycle
Apply container lifecycle hooks
Initialize container ( There can also be hooks )

Temporary container : Online troubleshooting .
Some container base images . There is no way to troubleshoot online . Use temporary containers to enter this Pod. Temporary containers share Pod All of the . Temporary containers are Debug Some orders of , After troubleshooting , as long as exit Exit the container , Temporary containers are automatically deleted
for example :
Java:dump, jre 50mb.jdk 150mb
jre 50mb: jdk As a temporary container
Temporary containers need to be opened for feature gating --feature-gates="EphemeralContainers=true" In all components ,api-server、kubelet、scheduler、controller-manager All have to be configured
To use a temporary container :
1、 Declare a temporary container . Get ready json file
{
"apiVersion": "v1",
"kind": "EphemeralContainers",
"metadata": {
"name": "my-nginx666" // Appoint Pod Name
},
"ephemeralContainers": [{
"command": [
"sh"
],
"image": "busybox", //jre The need for jdk To debug
"imagePullPolicy": "IfNotPresent",
"name": "debugger",
"stdin": true,
"tty": true,
"terminationMessagePolicy": "File"
}]
}
2、 Use temporary containers , Just apply it
kubectl replace --raw /api/v1/namespaces/default/pods/my-nginx666【pod name 】/ephemeralcontainers -f ec.json
Four 、 static state Pod
stay /etc/kubernetes/manifests All the places put Pod.yaml file , Machine start up kubelet Start it yourself .
static state Pod Always guarding this machine
5、 ... and 、Probe Probe mechanism ( Health examination mechanism )
Three probes per container (Probe)
Start the probe ( It was added later ) One time successful probe . As long as the startup is successful
kubelet Use the start probe , To detect whether the application has started . If it is started, subsequent detection and inspection can be carried out . The slow container must specify the start probe .
Start the probe After success, you don't have to , The remaining survival probe and ready probe continue to operate
Survival probe
kubelet Using survival probes , To check whether the container is alive properly .( Some containers may deadlock 【 The application is running , But you can't continue with the next steps 】),
If the detection fails, the container will be restarted
initialDelaySeconds: 3600( The application may not be available for a long time ) 5( Short, fall into an infinite start cycle )
Ready probe
kubelet Use the ready probe , To check if the container is ready Well, you can receive traffic . When one Pod All the containers inside are ready , To put this Pod I'm ready . That's what it's for :Service Back end load balancing multiple Pod, If a Pod Not ready yet , It will start from service Load balancing
Who uses these probes to detect
kubelet Will actively follow the configuration to Pod All containers inside send response probe requests
Probe Configuration item
initialDelaySeconds
: How many seconds does the container have to wait after it starts to survive and be ready before the detector is initialized , The default is 0 second , The minimum is 0. This is for people who have notperiodSeconds
: The interval between probes ( The unit is seconds ). The default is 10 second . The minimum is 1.successThreshold
: After the detector failed , The minimum number of consecutive successes considered successful . The default value is 1.This value for the survival and start probe must be 1. The minimum is 1.
failureThreshold
: When the probe fails ,Kubernetes Number of retries . Abandoning in the case of survival detection means restarting the container . Abandonment in case of ready detection Pod Will be labeled as not ready . The default value is 3. The minimum is 1.timeoutSeconds
: How many seconds to wait after the timeout of detection . The default value is 1 second . The minimum is 1.
Official references : Configuration survives 、 Ready and start detector | Kubernetes
To write yaml Test probe mechanism
apiVersion: v1
kind: Pod
metadata:
name: "nginx-start-probe02"
namespace: default
labels:
app: "nginx-start-probe02"
spec:
volumes:
- name: nginx-vol
hostPath:
path: /app
- name: nginx-html
hostPath:
path: /html
containers:
- name: nginx
image: "nginx"
ports:
- containerPort: 80
startupProbe:
exec:
command: ["/bin/sh","-c","cat /app/abc"] ## Return no 0, That's detection failure
# initialDelaySeconds: 20 ## The probe will not be executed until the specified second
periodSeconds: 5 ## Run this every few seconds
timeoutSeconds: 5 ## Probe timeout , When the timeout is reached, the probe has not returned the result, indicating that it failed
successThreshold: 1 ## Success threshold , Success is success after several successive successes
failureThreshold: 3 ## Failure threshold , It's a real failure to fail several times in a row
volumeMounts:
- name: nginx-vol
mountPath: /app
- name: nginx-html
mountPath: /usr/share/nginx/html
livenessProbe: ## nginx Is there a container /abc.html, Ready probe
# httpGet:
# host: 127.0.0.1
# path: /abc.html
# port: 80
# scheme: HTTP
# periodSeconds: 5 ## Run this every few seconds
# successThreshold: 1 ## Success threshold , Success is success after several successive successes
# failureThreshold: 5 ## Failure threshold , It's a real failure to fail several times in a row
exec:
command: ["/bin/sh","-c","cat /usr/share/nginx/html/abc.html"] ## Return no 0, That's detection failure
# initialDelaySeconds: 20 ## The probe will not be executed until the specified second
periodSeconds: 5 ## Run this every few seconds
timeoutSeconds: 5 ## Probe timeout , When the timeout is reached, the probe has not returned the result, indicating that it failed
successThreshold: 1 ## Success threshold , Success is success after several successive successes
failureThreshold: 3 ## Failure threshold , It's a real failure to fail several times in a row
readinessProbe: ## Readiness test , All are http
httpGet:
# host: 127.0.0.1 ### no way
path: /abc.html ## Send a request to the container
port: 80
scheme: HTTP ## Return no 0, That's detection failure
initialDelaySeconds: 2 ## The probe will not be executed until the specified second
periodSeconds: 5 ## Run this every few seconds
timeoutSeconds: 5 ## Probe timeout , When the timeout is reached, the probe has not returned the result, indicating that it failed
successThreshold: 3 ## Success threshold , Success is success after several successive successes
failureThreshold: 5 ## Failure threshold , It's a real failure to fail several times in a row
# livenessProbe:
# exec: ["/bin/sh","-c","sleep 30;abc "] ## Return no 0, That's detection failure
# initialDelaySeconds: 20 ## The probe will not be executed until the specified second
# periodSeconds: 5 ## Run this every few seconds
# timeoutSeconds: 5 ## Probe timeout , When the timeout is reached, the probe has not returned the result, indicating that it failed
# successThreshold: 5 ## Success threshold , Success is success after several successive successes
# failureThreshold: 5 ## Failure threshold , It's a real failure to fail several times in a row
边栏推荐
- AI chief architect 8-aica-gao Xiang, in-depth understanding and practice of propeller 2.0
- Super Jumping! Jumping! Jumping!
- Redis deployment under Linux & redis startup
- Cloudcompare & PCL point cloud SVD decomposition
- IO error in Oracle11g: got minus one from a read call
- 隐私计算FATE-----离线预测
- Usage record of Xintang nuc980: self made development board (based on nuc980dk61yc)
- AWS builds a virtual infrastructure including servers and networks (2)
- Not so Mobile
- B_ QuRT_ User_ Guide(30)
猜你喜欢
Love analysis released the 2022 love analysis · it operation and maintenance manufacturer panorama report, and an Chao cloud was strongly selected!
Unity gets the coordinate point in front of the current object at a certain angle and distance
块级元素上下左右居中的两个小技巧
887. egg drop
Set the icon for the title section of the page
B_ QuRT_ User_ Guide(26)
B_ QuRT_ User_ Guide(28)
安装nrm后,使用nrm命令报错internal/validators.js:124 throw new ERR_INVALID_ARG_TYPE(name, ‘string‘, value)
Selenium+chromedriver cannot open Google browser page
PMP从报考到拿证基本操作,了解PMP必看篇
随机推荐
如何抑制SiC MOSFET Crosstalk(串扰)?
Infinite penetration test
块级元素上下左右居中的两个小技巧
Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...
新唐NUC980使用记录:自制开发板(基于NUC980DK61YC)
【学习笔记】差分约束
11grac turn off archive log
How to choose an account opening broker? Is it safe to open an account online?
Case tool
B_ QuRT_ User_ Guide(30)
【无标题】
Tree
Not so Mobile
探讨gis三维系统在矿山行业中的应用
TCP
Quelle est la largeur de bande du serveur de bavardage sonore pour des centaines de millions de personnes en même temps?
[learning notes] shortest path + spanning tree
[go ~ 0 to 1] on the first day, June 24, variables, conditional judgment cycle statement
Selenium reptile
[go ~ 0 to 1] the third day June 27 slice, map and function