pod的健康检测
可通过三种探针,LIvenessProbe,ReadinessProbe和StartupProbe
- livenessProbe, 判断容器是否存在running,如果探测不到健康,kubelet就会杀掉该容器,根据重启策略处理额,如果容器中没有设置该探针,则LivenessProbe一直返回success
- ReadinnessProbe 用于判断容器服务是否可用(Read状态),如果发现不可用,自动将其从Service中后端EndPoint列表中隔离出去,后续把恢复到Ready状态的再加回来,该探针是定期触发的
- StartupProbe ,主要用于有且只有一次的超长延时,比如要与远服务器建立网络连接
探针的三种配置
- ExecAction:在容器内运行一个命令,如果该命令返回码为0,则健康
- TCPSoketAction:容器IP地址和端口来执行TCP检测,如果能建立连接,则健康
- HTTPGETAction: 通过容器的IP地址,端口 ,调用http的GET方法,响应状态码在 200 <= code < 400,则健康
apiVersion: v1 kind: Pod metadata: labels: test: liveness name: liveness-exec spec: containers: - name: liveness image: nginx #方式1:通过检测health文件是否存在 #args: #- /bin/bash #- -c #- echo ok > /tmp/health; sleep 10; # rm -rf /tmp/health; sleep 600 #livenessProbe: # exec : # command: # - cat # - /tmp/health # #首次健康检测的等待时间 #initialDelaySeconds: 15 #超时时间 #timeoutSeconds : 1 #方式二,通过tcp湍口 ports: - containerPort: 80 #livenessProbe: # tcpSocket: # port: 80 # initialDelaySeconds: 15 # timeoutSeconds : 1 #方式三,通过调用http Get 方法 livenessProbe: httpGet: path: /_status/healthz port: 80 initialDelaySeconds: 15 timeoutSeconds : 1
NodeSelector 定向调度
设置标签
//给节点scms01增加标签zone=north2
kubectl label nodes scms01 zone=north2
也可以设置在yaml文件中
查看标签
kubectl get node --show-labels
NAME STATUS ROLES AGE VERSION LABELS
scms01 Ready control-plane 17d v1.26.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=scms01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers=,zone=north
scms02 Ready <none> 17d v1.26.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=scms02,kubernetes.io/os=linux,zone=north
NodeAffinity: Node亲和性调度
apiVersion: v1
kind: Pod
metadata:
name: with-node-affinity
spec:
affinity:
nodeAffinity:
#必须满足规则才可以调度pod到Node上
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/arch
operator: In
values:
- amd64
#优先满足指定规则,调度器会尝试调度pod到Node上,但不强求
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: disk-type
operator: In
values:
- ssd
containers:
- name: with-node-affinity
image: mysql
~