如何在Kubernetes yaml文件中作为命令运行脚本 [英] How to run a script as command in Kubernetes yaml file

查看:1411
本文介绍了如何在Kubernetes yaml文件中作为命令运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个脚本.一个Pod将有两个容器,一个用于主应用程序,另一个用于日志记录.我希望日志记录容器进入睡眠状态以帮助我调试问题.

I have this script. A Pod will have two containers, one for the main application and the other for logging. I want the logging container to sleep to help me debug an issue.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: codingjediweb
spec:
  replicas: 2
  selector:
    matchLabels:
      app: codingjediweb
  template:
    metadata:
      labels:
        app: codingjediweb
    spec:
      volumes:
      - name: shared-logs
        emptyDir: {}
      containers:
      - name: codingjediweb
        image: docker.io/manuchadha25/codingjediweb:03072020v2
        volumeMounts:
        - name: shared-logs
          mountPath: /deploy/codingjediweb-1.0/logs/
        env:
        - name: db.cassandraUri
          value: cassandra://xx.yy.xxx.yyy:9042
        - name: db.password
          value: 9__
        - name: db.keyspaceName
          value: somei
        - name: db.username
          value: supserawesome
        ports:
        - containerPort: 9000
      - name: logging
        image: busybox
        volumeMounts:
        - name: shared-logs
          mountPath: /deploy/codingjediweb-1.0/logs/
        command: ["tail -f /deploy/codingjediweb-1.0/logs/*.log"]

在运行tail -f ...之前,我想添加一个sleep/delay以避免出现竞争情况(由于日志文件不存在,因此应用程序需要一段时间才能记录日志,并且tail -f同时失败.我可以运行这样的脚本-while true; do sleep 86400; done .

Before running tail -f ..., I want to add a sleep/delay to avoid a race condition (the application takes sometime before logging and tail -f fails in the meanwhile because the log file doesn't exist. Alternatively, I am ok to run a script like this - while true; do sleep 86400; done .

我该怎么做?

推荐答案

明白了-必须做command: ['sh', '-c', "while true; do sleep 86400; done"]

这篇关于如何在Kubernetes yaml文件中作为命令运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆