kube配置文件无效。在pod中使用kubernetes客户端python时未找到任何配置

kube配置文件无效。在pod中使用kubernetes客户端python时未找到任何配置,kubernetes,kubectl,Kubernetes,Kubectl,我正试图从pod中获取kubernetes api服务器 这是我的吊舱配置 apiVersion: batch/v1beta1 kind: CronJob metadata: name: test spec: schedule: "*/5 * * * *" jobTemplate: spec: template: spec: containers: - name: test

我正试图从pod中获取kubernetes api服务器

这是我的吊舱配置

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: test
spec:
  schedule: "*/5 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: test
            image: test:v5
            env:
            imagePullPolicy: IfNotPresent
            command: ['python3']
            args: ['test.py']
          restartPolicy: OnFailure
下面是test.py中的kubernetes客户端python代码

from kubernetes import client, config

# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()

v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
    print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
但我得到了这个错误:

kubernetes.config.config_exception.ConfigException: Invalid kube-config file. No configuration found.

当在集群中运行时,您需要
load\u incluster\u config()

当在集群中运行时,您需要
load\u incluster\u config()

谢谢,错误消失了,但我看到了这个know kubernetes.client.exceptions.ApiException:(403)原因:禁止的HTTP响应主体:{“种类”:“状态”,“apiVersion”:“v1”,“元数据”:{},“状态”:“失败”,“消息”:”pods是禁止的:您需要使用各种角色/绑定类型为其设置ServiceAccount和RBAC权限,就像您将权限授予人一样。我如何才能做到这一点?您有任何示例吗?请参阅以获取起点。我的意思是,我需要在python代码中进行更改吗?谢谢,错误消失了,但我没有e此了解kubernetes.client.exceptions.ApiException:(403)原因:禁止HTTP响应正文:{“种类”:“状态”,“apiVersion”:“v1”,“元数据”:{},“状态”:“失败”,“消息”:“禁止pods:您需要使用各种角色/绑定类型为其设置ServiceAccount和RBAC权限,就像您将权限授予人一样。我如何才能做到这一点?您有任何示例吗?请参阅以获取起点。我的意思是,我需要在python代码中进行更改吗?”?