Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unable to load kube config within an AWS Lambda #2403

Open
@supreme-core

Description

@supreme-core

What happened (please include outputs or screenshots):
I like to execute this code snippet within a lambda


"""
Creates a deployment using AppsV1Api from file nginx-deployment.yaml.
"""

from os import path

import yaml

from kubernetes import client, config


def handler(event, context):
    # Configs can be set in Configuration class directly or using helper
    # utility. If no argument provided, the config will be loaded from
    # default location.
    config.load_kube_config()

    with open(path.join(path.dirname(__file__), "yaml_dir/nginx-deployment.yaml")) as f:
        dep = yaml.safe_load(f)
        k8s_apps_v1 = client.AppsV1Api()
        resp = k8s_apps_v1.create_namespaced_deployment(
            body=dep, namespace="default")
        print(f"Deployment created. Status='{resp.metadata.name}'")

What you expected to happen:
I expect load_kube_config() to work

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:
I like to know how to create a Kubernetes deployment from within a Lambda
Environment:

  • Kubernetes version (kubectl version):
  • OS (e.g., MacOS 10.13.6):
  • Python version (python --version)
  • Python client version (pip list | grep kubernetes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/supportCategorizes issue or PR as a support question.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions