Keval Bhogayata
Keval Bhogayata

Reputation: 6736

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 !

Upvotes: 0

Views: 263

Answers (1)

Gerard Garcia
Gerard Garcia

Reputation: 1856

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

Upvotes: 2

Related Questions