用一个yaml示例pod的用法

apiVersion: v1
kind: Pod
metadata:
  name: stop-apps
spec:
  initContainers:
  - name: init
    image: busybox
    imagePullPolicy : IfNotPresent
    command: ['sh', '-c', ' echo "df -h > /root/running/yes.txt" > /tmp/app-a.sh;chmod +x /tmp/app-a.sh' ]
    volumeMounts:
    - name: app-running-volume
      mountPath: /tmp
  containers:
  - name: myapps
    image: centos:7.5.1804
    imagePullPolicy: IfNotPresent
    command: ['sh', '-c',' /root/running/app-a.sh; sleep 3600; ']
    volumeMounts:
    - name: app-running-volume
      mountPath: /root/running
    - name: app-logs-volume
      mountPath: /root/logs
    lifecycle:
      postStart:
        exec:
          command: ["bash", "-c", "echo begin >> /root/logs/message"]
      preStop:
        exec:
          command: ["bash", "-c", "echo Bye >> /root/logs/message"]
  volumes:
  - name: app-running-volume
    hostPath:
      path: /tmp/running
      type: Directory
  - name: app-logs-volume
    hostPath:
      path: /tmp/logs
      type: Directory
  nodeSelector:
    kubernetes.io/hostname: host-192-168-3-124
  • 安装: init container
  • 启动: 钩子postStart
  • 停止: 钩子prestop
  • 卸载: 钩子prestop

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注