zoukankan      html  css  js  c++  java
  • kubernetes 健康检查和初始化容器

    Pod-hook:
    postStart:
    1.
    $ $ vim preStart-hook.yaml
    ---
    apiVersion: v1
    kind: Pod
    metadata:
      name: hook-demo1
      labels:
        app: hook
    spec:
      containers:
      - name: hook-demo1
        image: nginx
        ports:
        - name: webport
          containerPort: 80
        lifecycle:
          postStart:
            exec:
              command: ["/bin/sh", "-c", "echo Hello from the postStart Hander > /usr/share/message"]

              
    $ kubectl exec hook-demo1  -i -t  /bin/bash          
    preStop:
    2.强制删除
    $ kubectl delete pod hook-demo1 --force --grace-period=0

    $ vim preStop-hook.yaml
    ---
    apiVersion: v1
    kind: Pod
    metadata:
      name: hook-demo2
      labels:
        app: hook
    spec:
      containers:
      - name: hook-demo2
        image: nginx
        ports:
        - name: webport
          containerPort: 80
        volumeMounts:
        - name: message
          mountPath: /usr/share
        lifecycle:
          preStop:
            exec:
              command: ["/bin/sh", "-c", "echo Hello from the postStop Hander > /usr/share/message"]
      volumes:
      - name: message
        hostPath:
          path: /tmp

    普通的pod是不能被调度到master节点上面来的


    存活探针:
    liveness probe
    $ vim liveness-exec.yaml
    ---
    apiVersion: v1
    kind: Pode
    metadata:
      name: liveness-exec
      labels:
        app: liveness
    spec:
      containers:
      - name: liveness
        images: busybox
        args:
        - /bin/sh
        - -c
        - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
        livenessProbe:
          exec:
            command:
            - cat
            - /tmp/healthy
          initialDelaySeconds: 5
          periodSeconds: 5

          
    初始化容器-initcontainer
    $ vim initpod1.yaml

    ---
    apiVersion: v1
    kind: Pod
    metadata:
      name: init-pod
      labels:
        app: init

    spec:
      initContainers:
      - name: init-myservice
        image: busybox
        command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; done;']
      - name:
        image: busybox
        command: ['sh', '-c', 'until nslookup mydb; do echo waiting for mydb; sleep 2; done;']
      containers:
      - name: main-container
        image: busybox
        command: ['sh', '-c', 'echo The app is running! && sleep 3600']
       

  • 相关阅读:
    根据进程id pid 查容器id
    jenkins 持续集成笔记1 --- 安装配置
    PMM 监控 MySQL 使用钉钉告警
    PMM 监控 MySQL
    docker HealthCheck健康检查
    顶层const和底层const
    Windows下使用VS2017搭建FLTK开发环境
    解决FAT32格式U盘安装win10时0x8007000D错误
    在VS中为C/C++源代码文件生成对应的汇编代码文件(.asm)
    VS2017设置主题和代码字体
  • 原文地址:https://www.cnblogs.com/fuyuteng/p/10906656.html
Copyright © 2011-2022 走看看