Pedro Machado
07/15/2021, 9:05 PMKubernetesRun
run config.
I wrote a task that reads the secrets from the file system. However, locally, I was using environment variables for secrets. I'll probably have to see a way to mount the secrets locally on the docker container but before I go too far down this path, I'd like to get some input from the community.
I suppose I could try to set up Kubernetes locally but I know very little about Kubernetes. This is my first experience with it.Kevin Kho
Pedro Machado
07/15/2021, 9:11 PMKevin Kho
Attempt to use a Prefect Secret that contains a Kubernetes API Key. If kubernetes_api_key_secret = None then it will attempt the next two connection methods. By default the value is KUBERNETES_API_KEY so providing None acts as an override for the remote connection. 2. Attempt in-cluster connection (will only work when running on a Pod in a cluster) 3. Attempt out-of-cluster connection using the default location for a kube config file
davzucky
07/16/2021, 1:10 AMPedro Machado
07/16/2021, 2:34 AMdavzucky
07/16/2021, 10:36 AMimport os
import distutils.util
from prefect.tasks.kubernetes import KubernetesSecret
from prefect.tasks.secrets import EnvVarSecret
from prefect import Flow, task
@task
def print_connection_string(connection_string: str):
print(f"Connection string => {connection_string}")
def get_flow(use_local_secret: bool = False) -> Flow:
with Flow("Sample Secret") as flow:
kSecret = KubernetesSecret(kubernetes_api_key_secret="")
con_str = (
EnvVarSecret("MONGO_URL")
if use_local_secret
else kSecret(secret_name="k8s_secrets", secret_key="MONGO_URL")
)
print_connection_string(con_str)
return flow
use_local_secret = bool(
distutils.util.strtobool(os.environ.get("USE_LOCAL_SECRET", "False"))
)
flow = get_flow(use_local_secret)
flow.run()
Pedro Machado
07/16/2021, 1:15 PM