文章预览
在应用中获取当前所在 kubernetes 的 namespace Intro 最近看到一篇文章获取在 Kuberbetes 中的 namespace 通过 kubectl 来获取,并且还要配置 token,觉得太复杂了,我们也有在应用中获取当前所在的 Kubernetes 的 namespace,在 kubernetes 中会有一个默认 in cluster 的配置,不过没有那么多的权限,如果要获取更多 kubernetes 中的信息需要配置 service account 配置 rbac 角色以及权限呢,但是获取当前 namespace 信息默认的权限就完全足够了 Sample 这里我先在 k8s 里跑一个 pod 来做一个测试 kubectl run dotnet-exec-playground --image=weihanli/dotnet-exec:0.23.0-web -- "WebApplication.Create().Run();" 借助 dotnet-exec 的容器镜像来在 k8s 里跑一个 pod,执行之后可以通过 kubectl logs / kubectl describe 来查看 pod 状态,这里直接查看 pod log kubectl logs dotnet-exec-playground > kubectl logs dotnet-exec-playground info: Microsoft.Hosti
………………………………