k 8 s nginx健康診断機能の導入(生存プローブ)

1648 ワード

1、k 8 sは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