Skip to content

Instantly share code, notes, and snippets.

@thibaultserti
Created January 28, 2024 12:05
Show Gist options
  • Save thibaultserti/156903fb2d4f8cd1bd863c25791b45d6 to your computer and use it in GitHub Desktop.
Save thibaultserti/156903fb2d4f8cd1bd863c25791b45d6 to your computer and use it in GitHub Desktop.
Kubernetes Call
from fastapi import FastAPI
from kubernetes import client, config
import uvicorn
app = FastAPI()
# Charger la configuration Kubernetes en utilisant le service account du pod
config.load_incluster_config()
# Obtenir la liste des namespaces
def get_namespaces():
v1 = client.CoreV1Api()
namespaces = v1.list_namespace()
return [namespace.metadata.name for namespace in namespaces.items]
# Route pour obtenir la liste des namespaces
@app.get("/namespaces")
def read_namespaces():
namespaces = get_namespaces()
return {"namespaces": namespaces}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
fastapi==0.109.0
kubernetes==29.0.0
uvicorn==0.27.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment