• 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']
       

  • 相关阅读:
    像asp.net Mvc一样开发nodejs+express Mvc站点
    js数组方法大全
    自己的时间规划
    7月暑假生活总结
    01. What Is Discrete Mathematics(中英字幕 by Ocean-藏心)
    找工作专题---二分查找
    angular.js 入门基础
    WCF实例管理
    是技术牛人,如何拿到国内IT巨头的Offer
    python
  • 原文地址:https://www.cnblogs.com/fuyuteng/p/10906656.html
Copyright © 2020-2023  润新知