Asking for help? Comment out what you need so we can get more information to help you!
Cluster information:
package main
import (
"log"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
// 设置日志
logFile, err := os.OpenFile("app.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening log file: %v", err)
}
defer logFile.Close()
log.SetOutput(os.Stdout)
log.Println("应用程序启动")
// 创建一个 channel 用于接收系统信号
sigs := make(chan os.Signal, 1)
// 监听 SIGTERM 和 SIGINT 信号
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
go func() {
// 等待接收信号
sig := <-sigs
log.Printf("收到信号: %s, 正在关闭应用程序...", sig)
// 模拟清理工作
time.Sleep(2 * time.Second)
log.Println("清理工作完成,应用程序已关闭")
time.Sleep(20 * time.Second)
os.Exit(0)
}()
// 模拟应用程序的主循环
for {
log.Println("应用程序正在运行...")
time.Sleep(1000 * time.Second)
}
}
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: pod
spec:
containers:
- name: container
image: registry.cn-hangzhou.aliyuncs.com/hxpdocker2/term:1.0
terminationMessagePath: "/dev/my-termination-message"
terminationMessagePolicy: "File"
volumeMounts:
- mountPath: /dev/my-termination-message
name: volume
imagePullPolicy: Always
nodeSelector:
kubernetes.io/os: linux
os:
name: linux
volumes:
- name: volume
hostPath:
path: /dev/my-termination-message
type: FileOrCreate
EOF
Kubernetes version:
Cloud being used: (put bare-metal if not on a public cloud)
Installation method:
Host OS:
CNI and version:
CRI and version:
You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.