从 pod 调用 Kubernetes Cron 作业

标签 kubernetes

是否可以在 pod 内调用 kubernetes Cron 作业。就像我必须从 pod 中运行的应用程序运行这项作业一样。

我是否必须在 pod 内使用 kubectl 来执行作业。

感谢您的帮助

最佳答案

Use the Default Service Account to access the API server. When you create a pod, if you do not specify a service account, it is automatically assigned the default service account in the same namespace. If you get the raw json or yaml for a pod you have created (for example, kubectl get pods/ -o yaml), you can see the spec.serviceAccountName field has been automatically set.

You can access the API from inside a pod using automatically mounted service account credentials, as described in Accessing the Cluster. The API permissions of the service account depend on the authorization plugin and policy in use.

In version 1.6+, you can opt out of automounting API credentials for a service account by setting automountServiceAccountToken: false on the service account

https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/

  1. 因此第一个任务是向 pod 的默认服务帐户授予执行您需要创建的操作的权限,或者创建一个自定义服务帐户并在 pod 内使用它

  2. 使用该服务帐户以编程方式访问 API 服务器以创建您需要的作业

  3. 这可能只是从 pod 内部向 API 服务器发送一个简单的curl POST,并使用用于创建作业的 json

How do I access the Kubernetes api from within a pod container?

您还可以使用特定于应用程序的 SDK,例如,如果您有一个 python 应用程序,则可以导入 kubernetes 并运行该作业。

关于从 pod 调用 Kubernetes Cron 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56994478/

相关文章:

docker - MDNS 从 kubernetes 内部广播?

docker - Java : Connecting to Redis cluster running in minikube

kubernetes - 如何让 Istio VirtualService 通过 header 和 uri 改变路由

docker - 如何在多节点集群上的 Kubernetes Pod 中使用 ConfigMap 放置整个目录及其子目录?

kubernetes - 手动创建和编辑 Kubernetes 对象

kubernetes - Kubectl 申请 revHistoryLimit 0 的部署不会删除旧的副本集

amazon-web-services - kubernetes + coreos 集群 - 替换证书

kubernetes - k3s支持ServiceTopology功能吗?

kubernetes - Rancher:即使在管理零群集的情况下,CPU利用率也很高

image - Kubernetes kubectl 设置镜像部署无法--记录历史记录?