Kubernetes 如何在 Docker 容器内运行(kubectl 没有得到)?
我知道它必须与 API 服务器通信,但我找不到包含此详细信息的配置文件(例如在我的用户下找到的 .kube/config 文件)
我已经做了一个 env 来检查设置了哪些变量。 我已经转到主目录,其中有一个 .kube 目录,但没有配置文件。
最佳答案
The recommended way to authenticate to the apiserver is with a service account credential. By kube-system, a pod is associated with a service account, and a credential (token) for that service account is placed into the filesystem tree of each container in that pod, at /var/run/secrets/kubernetes.io/serviceaccount/token
当 kubectl 使用 serviceaccount 与 api 连接时 - token 放置在 /var/run/secrets/kubernetes.io/serviceaccount/token
When you create a pod, if you do not specify a service account, it is automatically assigned the default service account in the same namespace
当您使用 kubectl 执行“配置操作”时,如下所示:
kubectl config set-context test
.kube/config 将自动创建。
您还可以将不同的 serviceAccountName 传递到您的 Pod 和自动挂载 token 中,例如:
spec:
serviceAccountName: <your_service_account>
automountServiceAccountToken: true
您可以找到有关为 Pod 配置服务帐户的更多信息 here .
希望这有帮助。
关于linux - kubernetes 如何在 docker 容器内工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56241274/