k8s部署nginx健康检查功能(存活探针)

1、k8s部署nginx的yaml文件
1.1、nginx健康检查使用tcpSocket:方式

[root@k8s-node1 yaml_file]# cat nginx_lp.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mynginx
spec:
  replicas: 1
  selector:
    matchLabels:
      name: mynginx
  template:
    metadata:
      labels:
        name: mynginx
    spec:
      containers:
        - name: mynginx
          image: nginx:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
          livenessProbe:
            tcpSocket:
              port: 80
            initialDelaySeconds: 45   #pod启动后45s后执行第一次检查
            periodSeconds: 15       #第一次检查后每隔15s进行检查一次
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  type: NodePort
  selector:
    name: nginx

1.2、nginx健康检查使用httpGet方式

[root@k8s-node1 yaml_file]# cat nginx_lp.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mynginx
spec:
  replicas: 1
  selector:
    matchLabels:
      name: mynginx
  template:
    metadata:
      labels:
        name: mynginx
    spec:
      containers:
        - name: mynginx
          image: nginx:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 10
            periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  type: NodePort
  selector:
    name: nginx

你可能感兴趣的:(k8s_docker)