简体   繁体   中英

Allow docker app to access kubectl pointed cluster

My local system's kubectl is currently pointing to my digitalocean kubernetes cluster. 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.

Now, I dockerized this application, so now it is running as a container.

How can I configure my docker-compose in such a way, so that it can access local system's 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

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 ).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM