[英]Allow docker app to access kubectl pointed cluster
My local system's kubectl is currently pointing to my digitalocean kubernetes cluster.我本地系统的 kubectl 当前指向我的 digitalocean kubernetes 集群。 I wrote an app in Rust that can list the pods on my cluster and their CPU usage, which is working fine on local system.
我用 Rust 编写了一个应用程序,它可以列出我集群上的 pod 及其 CPU 使用率,这在本地系统上运行良好。
Now, I dockerized this application, so now it is running as a container.现在,我 dockerized 这个应用程序,所以现在它作为容器运行。
How can I configure my docker-compose in such a way, so that it can access local system's kubectl ?如何以这种方式配置我的 docker-compose,以便它可以访问本地系统的 kubectl ?
I tried this on the basis of suggested solutions:我根据建议的解决方案尝试了这个:
version: "3.3"
services:
custom-tool:
container_name: custom-tool
image: myimage:v16
restart: always
command: ./main-thread
environment:
- KUBECONFIG=/root/config
volumes:
- /home/keval/.kube/config:/root/config
But, no luck yet !但是,还没有运气!
It seems like you can create your own configuration programmatically, have it read from ~/.kube/config
or from env variables: https://docs.rs/kube/0.73.0/kube/struct.Config.html似乎您可以通过编程方式创建自己的配置,从
~/.kube/config
或 env 变量中读取: https ://docs.rs/kube/0.73.0/kube/struct.Config.html
The easiest option you have is to have your local .kube/config
available inside your container by using a bind mount (most likely at /root/.kube/config
).最简单的选择是使用绑定挂载(最有可能在
/root/.kube/config
)在容器中使用本地.kube/config
。
It will look like this:它看起来像这样:
version: "3.3"
services:
custom-tool:
container_name: custom-tool
image: myimage:v16
restart: always
command: ./main-thread
volumes:
- type: bind
source: /home/keval/.kube/config
target: /root/.kube/config
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.