相关文章推荐
活泼的柚子  ·  Type.GetProperties 方法 ...·  2 月前    · 
阳光的青蛙  ·  Spring ...·  1 年前    · 

I am deploying my Microservices on Kubernetes Cluster. Every Application has 4 replicas or PODS. For a REST API in 1 application, I want to track which POD addressed my request. e.g. my /app/deploy(body contains app_id) request is handled by POD1.

For the same, I have imported Kubernetes jar in my application. In my code, I want to check the current POD on which this code is running.

I want an API like kubernetesDiscoveryClient.getCurrentPOD(), something of this sort.

This worked for me.

podName = Optional.ofNullable(System.getenv("HOSTNAME"));

I am deploying my Microservices on Kubernetes Cluster. Every Application has 4 replicas or PODS. For a REST API in 1 application, I want to track which POD addressed my request. e.g. my /app/deploy(bo... 在使用kubernates的sdk。client- java 去访问 kubernetes 时。遇到了问题就是。我想通过 pod Name同时 获取 多个 pod 。找了很久没找到解决方法。最后自己摸索出来了。记录一下。方便其他人排查。 通过labelSelector 获取 某个 pod labelName=xxx api.list Pod ForAllNamespaces( null, null, "appName...
你可以使用kubectl logs命令来 获取 Kubernetes Pod 资源的日志。例如,要 获取 名为my- pod Pod 的日志,可以运行以下命令: kubectl logs my- pod 如果要 获取 特定容器的日志,可以使用-c选项指定容器名称。例如,要 获取 名为my-container的容器的日志,可以运行以下命令: kubectl logs my- pod -c my-container 如果要 获取 最近的日志条目,可以使用-f选项来跟踪日志输出。例如,要跟踪名为my- pod Pod 的日志,可以运行以下命令: kubectl logs -f my- pod 至于 获取 日志的脚本,你可以编写一个简单的bash脚本来调用kubectl logs命令并将输出保存到文件 。以下是一个示例脚本: #!/bin/bash # Set variables pod _name="my- pod " container_name="my-container" log_file="my-log.txt" # Get logs and save to file kubectl logs $ pod _name -c $container_name > $log_file 注意,这只是一个简单的示例脚本,你需要根据自己的需求进行修改和定制。