Last active
October 4, 2018 13:40
-
-
Save linnil1/9795c20bec2065adc8306ee57093fdae to your computer and use it in GitHub Desktop.
Use PYTHON API in Kubernetes pod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
kind: ClusterRole | |
apiVersion: rbac.authorization.k8s.io/v1 | |
metadata: | |
name: myapi-k8s | |
rules: | |
- apiGroups: [""] # "" indicates the core API group | |
resources: ["pods"] | |
verbs: ["get", "watch", "list"] | |
--- | |
kind: ClusterRoleBinding | |
apiVersion: rbac.authorization.k8s.io/v1 | |
metadata: | |
name: myapi-k8s | |
subjects: | |
- kind: ServiceAccount | |
name: myapi-k8s | |
namespace: default | |
roleRef: | |
kind: ClusterRole | |
name: myapi-k8s | |
apiGroup: rbac.authorization.k8s.io | |
--- | |
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: myapi-k8s | |
--- | |
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: test-k8s | |
spec: | |
serviceAccountName: myapi-k8s | |
containers: | |
- name: test-k8s | |
image: python:3.7-slim | |
command: [tail] | |
args: ['-f', '/dev/null'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kubernetes import client, config | |
config.load_incluster_config() | |
v1 = client.CoreV1Api() | |
ret = v1.list_pod_for_all_namespaces(watch=False) | |
print(ret.items[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment