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

Skip to content

Commit 1edf499

Browse files
authored
Merge pull request kubernetes-client#610 from tomplus/feat/in-cluster-example
feat: improve in-cluster-config example
2 parents cf33f41 + f9d5c93 commit 1edf499

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

examples/in_cluster_config.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,46 @@
1313
# limitations under the License.
1414

1515
# Simple example to show loading config from the cluster
16+
#
17+
# It works only from a pod. You can start an image with Python
18+
# (for example python:latest), exec into the pod, install the library,
19+
# then try out this example.
20+
#
21+
# If you get 403 errors from API server you will have to configure
22+
# RBAC to add the permission to list pods.
23+
#
24+
# ---
25+
# kind: ClusterRole
26+
# apiVersion: rbac.authorization.k8s.io/v1
27+
# metadata:
28+
# name: pods-list
29+
# rules:
30+
# - apiGroups: [""]
31+
# resources: ["pods"]
32+
# verbs: ["list"]
33+
# ---
34+
# kind: ClusterRoleBinding
35+
# apiVersion: rbac.authorization.k8s.io/v1
36+
# metadata:
37+
# name: pods-list
38+
# subjects:
39+
# - kind: ServiceAccount
40+
# name: default
41+
# namespace: default
42+
# roleRef:
43+
# kind: ClusterRole
44+
# name: pods-list
45+
# apiGroup: rbac.authorization.k8s.io
46+
# ---
47+
#
48+
# Doc: https://kubernetes.io/docs/reference/access-authn-authz/rbac/
1649

1750
from kubernetes import client, config
1851

1952

2053
def main():
54+
55+
# it works only if this script is run by K8s as a POD
2156
config.load_incluster_config()
2257

2358
v1 = client.CoreV1Api()

0 commit comments

Comments
 (0)