Giter VIP home page Giter VIP logo

Comments (2)

tanmaykm avatar tanmaykm commented on July 22, 2024

That should be possible. A pod typically uses the service account token made available to it. If the kubernetes configuration is set to mount the token, it should be available at the path /var/run/secrets/kubernetes.io/serviceaccount/token inside the container. The other pieces if information you would need to connect are the namespace and CA certificate to validate the conenction. They should also be mounted into the container. So to summarize, the mounted locations to look at are:

  • /var/run/secrets/kubernetes.io/serviceaccount/namespace : for namespace
  • /var/run/secrets/kubernetes.io/serviceaccount/ca.crt : for CA certificate
  • /var/run/secrets/kubernetes.io/serviceaccount/token : for the authentication token

Then the code to connect to the API server should look like:

ns_mount = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
cacert_mount = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
token_mount = "/var/run/secrets/kubernetes.io/serviceaccount/token"
api_server = "https://kubernetes.default.svc"

# the cluster cacert should be installed at appropriate place in the pod instead of this
# NetworkOptions.jl has instructions on how to deal with certificates
ENV["JULIA_NO_VERIFY_HOSTS"] = "kubernetes.default.svc"

using Kuber
ctx = KuberContext()
token = string(readchomp(token_mount))
ns = string(readchomp(ns_mount))

set_server(ctx, api_server; headers=Dict("Authorization" => "Bearer " * token))
Kuber.set_ns(ctx, ns)
Kuber.set_api_versions!(ctx);

# ctx is now ready to use with Kuber.jl APIs
# ensure the serviceaccount token has enough permissions to execute the APIs

from kuber.jl.

chunjiw avatar chunjiw commented on July 22, 2024

Thank you very much! I will try it out soon. Close this issue for now; will reopen if I have further questions :) Thank you for this awesome project!

from kuber.jl.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.