Container containing python and kubernetes modules to query api
1M+
Container with installed python and kubernetes plugins.
from __future__ import print_function
from pprint import pprint
import kubernetes
import os
from kubernetes import config
from kubernetes.client.rest import ApiException
# load configuration from mounted k8s secrets
configuration = config.load_incluster_config()
# create an instance of the API class
api_instance = kubernetes.client.AppsV1Api(kubernetes.client.ApiClient(configuration))
name = os.environ['STATEFULSET'] # str | name of the StatefulSet
namespace = os.environ['TARGET_NAMESPACE'] # str | object name and auth scope, such as for teams and projects
pretty = 'false' # str | If 'true', then the output is pretty printed. (optional)
try:
api_response = api_instance.read_namespaced_stateful_set_status(name, namespace, pretty=pretty)
pprint(api_response)
except ApiException as e:
print("Exception when calling AppsV1Api->read_namespaced_stateful_set_status: %s\n" % e)
Example mounts a python script to container and executes it when starting.
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: mydeployment
namespace: mynamespace
spec:
selector:
matchLabels:
app: myapp
template:
metadata:
namespace: mynamespace
spec:
containers:
- name: python-kube-client
image: chris060986/python-kube-client:latest
imagePullPolicy: Always
command: [ "python"]
args: [ "/app/python/myScript.py" ]
env:
- name: STATEFULSET
value: stateful-set-name
- name: TARGET_NAMESPACE
value: namespace-of-stateful-set
volumeMounts:
- name: actacor-py-scripts
mountPath: /app/python
volumes:
- name: actacor-py-scripts
configMap:
name: kube-api-configmap
Content type
Image
Digest
Size
352.4 MB
Last updated
almost 8 years ago
docker pull chris060986/python-kube-client