V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Hyson2023
V2EX  ›  Kubernetes

k8s 如何根据 HOSTNAME 导出不同路径的 gc log

  •  
  •   Hyson2023 · 179 天前 · 685 次点击
    这是一个创建于 179 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有三个 pod ,想为每个 pod 导出单独的 gc log,发现这样配置不生效,是直接字符串替换了,没有传入环境变量,又不想在 dockerfile 中加 HOSTNAME 的环境变量,求助各位大佬怎么配置

     env:
                 - name: HOSTNAME
                    valueFrom:
                    fieldRef:
                        fieldPath: metadata.name
                 - name: JAVA_TOOL_OPTIONS
                   value: -Xloggc:/home/logs/gc.${HOSTNAME}.log
    
    4 条回复    2023-11-02 09:06:46 +08:00
    julyclyde
        1
    julyclyde  
       179 天前   ❤️ 1
    收集日志的时候区分 pod 名字啊;产生日志的时候用固定文件名
    kebyn
        2
    kebyn  
       179 天前
    [官方文档]( https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#use-environment-variables-to-define-arguments)有解释,需要使用$(VAR),而不是${VAR}引用变量
    ```
    Note: The environment variable appears in parentheses, "$(VAR)". This is required for the variable to be expanded in the command or args field.
    ```
    fisherwei
        3
    fisherwei  
       178 天前
    首先,k8s pod 不是自带 HOSTNAME 环境变量么,你为什么要再引入一次
    Hyson2023
        4
    Hyson2023  
    OP
       178 天前
    @fisherwei 因为没生效,所以我又重新定义了一次
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3685 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 78ms · UTC 10:34 · PVG 18:34 · LAX 03:34 · JFK 06:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.