简体   繁体   English

允许 docker app 访问 kubectl 指向的集群

[英]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.

相关问题 配置 kubectl 以到达 docker 上的集群 - configure kubectl to reach cluster on docker 仅允许使用docker通过Nginx访问Express应用 - Only allow access to express app through nginx with docker Docker:在集群上部署应用 - Docker: Deploying app on a cluster 没有'Access-Control-Allow-Origin'反应表达docker app - No 'Access-Control-Allow-Origin' react express docker app 授予对Docker Swarm集群的访问权限 - Give access to Docker Swarm cluster 允许docker容器访问Internet - Allow docker container to access the internet Kubernetes - 未启用 - 使用Docker for desktop(Windows 10)但“kubectl cluster-info”有效吗? 为什么? - Kubernetes - not enabled - with Docker for desktop (windows 10) but “kubectl cluster-info” works? Why? 我可以在 CI 中使用 kubectl 将本地 (CI) docker 映像推送到集群吗? - Can I push a local (CI) docker image to cluster using kubectl in CI? 由于“Access-Control-Allow-Origin”,无法从 React 应用程序的 docker 容器中获取 API - Cannot fetch from API inside docker container from react app due to 'Access-Control-Allow-Origin' 从 docker 容器内访问 Kubernetes 集群 - Access to a kubernetes cluster from inside a docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM