Giter VIP home page Giter VIP logo

new-pykube's Introduction

new-pykube

PyPI version Downloads Python Test

Pykube (new-pykube) is a lightweight Python 3.6+ client library for Kubernetes.

This is a fork of pykube-ng which is no longer maintained.

Features

  • HTTP interface using requests using kubeconfig for authentication
  • Python native querying of Kubernetes API objects

Installation

To install pykube, use pip:

pip install new-pykube

Interactive Console

The pykube library module can be run as an interactive console locally for quick exploration. It will automatically load ~/.kube/config to provide the api object, and it loads pykube classes (Deployment, Pod, ..) into local context:

python3 -m pykube
>>> [d.name for d in Deployment.objects(api)]

Usage

Query for all ready pods in a custom namespace:

import operator
import pykube

api = pykube.HTTPClient(pykube.KubeConfig.from_file())
pods = pykube.Pod.objects(api).filter(namespace="gondor-system")
ready_pods = filter(operator.attrgetter("ready"), pods)

Access any attribute of the Kubernetes object:

pod = pykube.Pod.objects(api).filter(namespace="gondor-system").get(name="my-pod")
pod.obj["spec"]["containers"][0]["image"]

Selector query:

pods = pykube.Pod.objects(api).filter(
    namespace="gondor-system",
    selector={"gondor.io/name__in": {"api-web", "api-worker"}},
)
pending_pods = pykube.objects.Pod.objects(api).filter(
    field_selector={"status.phase": "Pending"}
)

Watch query:

watch = pykube.Job.objects(api, namespace="gondor-system")
watch = watch.filter(field_selector={"metadata.name": "my-job"}).watch()

# watch is a generator:
for watch_event in watch:
    print(watch_event.type) # 'ADDED', 'DELETED', 'MODIFIED'
    print(watch_event.object) # pykube.Job object

Create a Deployment:

obj = {
    "apiVersion": "apps/v1",
    "kind": "Deployment",
    "metadata": {
        "name": "my-deploy",
        "namespace": "gondor-system"
    },
    "spec": {
        "replicas": 3,
        "selector": {
            "matchLabels": {
                "app": "nginx"
            }
        },
        "template": {
            "metadata": {
                "labels": {
                    "app": "nginx"
                }
            },
            "spec": {
                "containers": [
                    {
                        "name": "nginx",
                        "image": "nginx",
                        "ports": [
                            {"containerPort": 80}
                        ]
                    }
                ]
            }
        }
    }
}
pykube.Deployment(api, obj).create()

Delete a Deployment:

obj = {
    "apiVersion": "apps/v1",
    "kind": "Deployment",
    "metadata": {
        "name": "my-deploy",
        "namespace": "gondor-system"
    }
}
pykube.Deployment(api, obj).delete()

Check server version:

api = pykube.HTTPClient(pykube.KubeConfig.from_file())
api.version

Requirements

  • Python 3.6+
  • requests (included in install_requires)
  • PyYAML (included in install_requires)

Local Development

You can run pykube against your current kubeconfig context, e.g. local Minikube:

poetry install
poetry run python3
>>> import pykube
>>> config = pykube.KubeConfig.from_file()
>>> api = pykube.HTTPClient(config)
>>> list(pykube.Deployment.objects(api))

To run PEP8 (flake8) checks and unit tests including coverage report:

make test

License

The code in this project is licensed under the Apache License, version 2.0

Contributing

Easiest way to contribute is to provide feedback! We would love to hear what you like and what you think is missing. Create an issue and we will take a look. PRs are welcome.

Code of Conduct

In order to foster a kind, inclusive, and harassment-free community, this project follows the Contributor Covenant Code of Conduct.

Acknowledgments

Thanks to pykube-ng project authored by Henning Jacobs.

new-pykube's People

Contributors

brosner avatar hjacobs avatar fovty avatar pcm32 avatar vicgp-te avatar jayme-github avatar dependabot[bot] avatar paultiplady avatar ashcrow avatar nolar avatar davidsiefert avatar frewsxcv avatar iliakur avatar lukemassa avatar jtaeuber avatar piontec avatar nebirhos avatar phsiao avatar shashank-te avatar reflection avatar rajivm avatar adambom avatar sublimino avatar cdrage avatar paralin avatar jonathan-mayer avatar mnaser avatar zoidyzoidzoid avatar wnykuang avatar paxbit avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

new-pykube's Issues

cleanup repo

Issue

Repo content is currently inconsistent with actual repo status

Problem to solve

search for all wrong references:

  • pykube-ng -> pykube - decision needed - response from namespace owner of pykube on PyP is curently pending
  • Deprecated Elements: Identify all deprecated references and ensure they are either updated or removed.

Proposal

Replace old information with updated

Who can address the issue

Everyone, but solving the PyPI package namespace first is necessary

Automate Package Publishing to PyPI and Test PyPI Using GitHub Actions and API Tokens

Issue

Automate Package Publishing to PyPI and Test PyPI Using GitHub Actions and API Tokens

Problem to solve

Currently, the process for publishing packages to PyPI and Test PyPI involves manually setting environment variables for authentication. This can be error-prone and less secure. We need to automate the process in our GitHub Actions workflow using API tokens for secure and efficient package uploads.

Further details

  • Affects the build and deployment process of Python packages.
  • We will utilize the GitHub Secrets feature to securely store and access the API tokens.
  • This change will streamline the deployment process, reducing the chance of human error and improving security by avoiding direct password usage.

Proposal

  1. Generate API Tokens:

    • Generate API tokens for both PyPI and Test PyPI.
    • Add these tokens as secrets in the GitHub repository.
  2. Update GitHub Actions Workflow:

    • Modify the existing build-publish-package.yaml to use the stored API tokens for authentication.
    • Ensure the workflow handles both Test PyPI and PyPI uploads.

Who can address the issue

This issue can be addressed by a developer with experience in:

  • GitHub Actions workflows
  • Python package management with Poetry and Twine
  • Secure management of credentials using GitHub Secrets

Other links/references

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.