是否可以在 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/
因此第一个任务是向 pod 的默认服务帐户授予执行您需要创建的操作的权限,或者创建一个自定义服务帐户并在 pod 内使用它
使用该服务帐户以编程方式访问 API 服务器以创建您需要的作业
这可能只是从 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/