question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Load in cluster config by default

See original GitHub issue

Currently we have two method in config module to load config. One from kube config and the other from in-cluster configs. Either add in-cluster config load to load kube config or add a new method (maybe call it load_config or load for short) that tries in-cluster first and then kube-config.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
mbohloolcommented, Jun 15, 2017
from kubernetes import config
config.load_incluster_config()
...

Somebody should add an example for this in examples/ folder.

3reactions
jkinkeadcommented, Jun 15, 2017

I’d love to see this as part of the API. I implemented a version of this already; I’m happy to put this into a PR if you like:

# Prereqs:
# - import os
# - 'config' is the instance of  kubernetes.client.Configuration being initialized.

# Code:
# Load credentials from the environment.
base_creds_path = '/var/run/secrets/kubernetes.io/serviceaccount'
with open(os.path.join(base_creds_path, 'token')) as token_file:
    config.api_key['authorization'] = 'Bearer {}'.format(token_file.read())
config.ssl_ca_cert = os.path.join(base_creds_path, 'ca.crt')
# Load the "kubernetes" service items.
service_host = os.environ['KUBERNETES_SERVICE_HOST']
service_port = os.environ['KUBERNETES_SERVICE_PORT']
config.host = 'https://{}:{}'.format(service_host, service_port)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Organizing Cluster Access Using kubeconfig Files - Kubernetes
By default, kubectl looks for a file named config in the $HOME/.kube directory. You can specify other kubeconfig files by setting the ...
Read more >
How to use the kubernetes.config.load_incluster_config ... - Snyk
If no argument provided, the config will be loaded from # default location. print ("Initializing ...") if self.cluster_config == 'out-of-cluster': try: ...
Read more >
unable to load in-cluster configuration ... - Stack Overflow
this is because you are trying to get cluster config from outside of the cluster. When you run go run main.go , you...
Read more >
Cluster configuration (proto) — envoy 1.25.0-dev-abdbc4 ...
(Duration) The timeout for new network connections to hosts in the cluster. If not set, a default value of 5s will be used....
Read more >
Kubectl Config Set-Context | Tutorial and Best Practices
This allows you to define multiple contexts in your configuration file, which you can then use to target multiple Kubernetes clusters, or the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found