[英]Allow docker app to access kubectl pointed cluster
我本地系統的 kubectl 當前指向我的 digitalocean kubernetes 集群。 我用 Rust 編寫了一個應用程序,它可以列出我集群上的 pod 及其 CPU 使用率,這在本地系統上運行良好。
現在,我 dockerized 這個應用程序,所以現在它作為容器運行。
如何以這種方式配置我的 docker-compose,以便它可以訪問本地系統的 kubectl ?
我根據建議的解決方案嘗試了這個:
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
但是,還沒有運氣!
似乎您可以通過編程方式創建自己的配置,從~/.kube/config
或 env 變量中讀取: https ://docs.rs/kube/0.73.0/kube/struct.Config.html
最簡單的選擇是使用綁定掛載(最有可能在/root/.kube/config
)在容器中使用本地.kube/config
。
它看起來像這樣:
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.