Package: pykubeks
pykubeksThis is a fork ofpykubewhich
is no longer maintained.  If you are interested in who brought that
lovely little library into the world, please check outThe Kel Project.The reason for this fork is to release the AWS EKS support I wrote for
the original project, before it was abandoned.  The new namepykubeksis a portmanteau ofpykubeandEKS.The python package name is still the same to make it simpler to "upgrade"
to this new version which supports user credentials supplied from client-go
credential plugins.  Seek8s documentationfor details.FeaturesHTTP interface using requests using kubeconfig for authenticationPython native querying of Kubernetes API objectsInstallationTo install pykubeks, use pip:pip install pykubeksUsageQuery for all ready pods in a custom namespace:importoperatorimportpykubeapi=pykube.HTTPClient(pykube.KubeConfig.from_file("/Users/<username>/.kube/config"))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:forwatch_eventinwatch:print(watch_event.type)# 'ADDED', 'DELETED', 'MODIFIED'print(watch_event.object)# pykube.Job objectCreate a ReplicationController:obj = {
    "apiVersion": "v1",
    "kind": "ReplicationController",
    "metadata": {
        "name": "my-rc",
        "namespace": "gondor-system"
    },
    "spec": {
        "replicas": 3,
        "selector": {
            "app": "nginx"
        },
        "template": {
            "metadata": {
                "labels": {
                    "app": "nginx"
                }
            },
            "spec": {
                "containers": [
                    {
                        "name": "nginx",
                        "image": "nginx",
                        "ports": [
                            {"containerPort": 80}
                        ]
                    }
                ]
            }
        }
    }
}
pykube.ReplicationController(api, obj).create()Delete a ReplicationController:obj={"apiVersion":"v1","kind":"ReplicationController","metadata":{"name":"my-rc","namespace":"gondor-system"}}pykube.ReplicationController(api,obj).delete()Check server version:api=pykube.HTTPClient(pykube.KubeConfig.from_file("/Users/<username>/.kube/config"))api.versionHTTPiepykube can be used together with HTTPie for Kubernetes command line querying goodness. For example:pip install httpie
http pykube://minikube/api/v1/servicesThe above example will construct an HTTP request to the cluster behind theminikubecontext and
show you the response containing all services.RequirementsPython 2.7 or 3.3+requests (included ininstall_requires)PyYAML (included ininstall_requires)LicenseThe code in this project is licensed under the Apache License, version 2.0
(included in this repository under LICENSE).ContributingBy making a contribution to this project, you are agreeing to theDeveloper Certificate of Origin v1.1(also included in this repository under DCO.txt).Developer Certificate of Origin v1.1Code of ConductContributor Covenant Code of ConductCommercial SupportNo commercial support is available for this project.