kube-config 文件无效。在 pod 中使用 kubernetes 客户端 python 时找不到配置

卡洛斯

我正在尝试从 pod 获取 kubernetes api 服务器。

这是我的 pod 配置

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-client 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_incluster_config()改为。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用 kubernetes 客户端 API 创建 pod 时出错

无法连接到kubernetes python api-找不到.kube / config文件

使用 Kubernetes Python 客戶端加載 kubect 配置文件返回錯誤:無效的 kube-config 文件

在客户端go中读取kubernetes pod的日志时找不到资源

Python kubernetes 客户端获取 pod Ready 状态时间

如何使用Golang客户端从Kubernetes驱逐或删除Pod

Kubernetes使用客户端API记录特定Pod

我需要使用kubernetes python客户端获取Kubernetes集群中Pod的资源使用情况

如何使用官方Python客户端从Pod中找到同一节点上的所有Kubernetes Pod?

kubernetes Python API客户端:执行完整的Yaml文件

如何使用Kubernetes Python客户端创建秘密?

使用python客户端删除Kubernetes资源

无法使用Kubernetes Python客户端创建CRD

如何通过python客户端获取kubernetes中的pod的日志和描述

使用Go客户端获取Kubernetes中Pod的当前资源使用情况

如何使用 Kubernetes Go 客户端调用 Pod 代理动词?

我想在pod内使用fabric8 kubernetes客户端(java)。我如何获得其所部署集群的kubernetes客户端?

如何在 .kube/config 中使用生成的 kubeconfig 文件

在OpenIdDict中使用客户端凭据时,指定的令牌无效是无效的

使用 elasticsearch 客户端时主机头无效

如何使用Kubernetes Python客户端连接到Google Kubernetes引擎

将 spring-cloud-starter-kubernetes-config 添加为依赖项时抛出 Kubernetes 客户端(证书)异常

在 Spring Config 客户端使用属性

使用Kubernetes JavaScript客户端的createDeployment()

在部署中使用Kubernetes javascript客户端创建作业

Kubernetes客户端Go找不到模块

“未配置文件端点。” 尝试使用模拟器在Azure存储中使用文件客户端时

使用带有 GKE 的 kubernetes python 客户端在 python 上实现 try/except

无效的主机。要浏览 Nexus,请单击此处/。要使用 Docker 注册表,请在访问 kubernetes 中的 nexus 时将您的客户端指向