Created
January 28, 2024 12:05
-
-
Save thibaultserti/156903fb2d4f8cd1bd863c25791b45d6 to your computer and use it in GitHub Desktop.
Kubernetes Call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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